Aller au contenu principal
Recette numéro 195

Recettes · Chapitre 10 · Sortie et intégration

Un livre tunnel de vingt feuillets de profondeur

Dix-neuf fenêtres rondes découpées avec dieCuts, chacune plus petite que la précédente : de la couverture, on voit à travers vingt plans jusqu’à un cerf.

Sur cette page
Niveau
Avancé
Postext
Testé avec Postext 1.84.0
Nécessite ≥ 1.84.0 · postext-pdf ≥ 1.84.0
Licence
Mis à jour le 13 nov. 2026
Code MIT · Texte CC BY 4.0
  • Exemple en anglais : pas encore d’édition française
  • Format 150 × 150 mm
  • 1 colonne
  • Cormorant Garamond 14/17
  • Lora
  • 40 pages
  • Niveau
  • Postext 1.84.0
  • Mis en page en 6 ms
  • 166 lignes de code

En bref

Un épais livre cartonné sur une promenade en forêt. Chaque feuillet a un trou rond un peu plus petit que le précédent, et depuis la couverture on voit jusqu’à la dernière page.

Ce que vous allez composer

Au fond du bois, un livre tunnel de vingt feuillets cartonnés sur un carré de 150 mm. Chaque recto est un plan d’un bois peint (chênes, digitales, un rouge-gorge, un renard dans les fougères, une chouette, des bouleaux), percé d’une fenêtre ronde un peu plus petite que la précédente, toutes sur le même centre. Le dernier plan est entier : une biche et son faon à une mare de la clairière. Depuis la couverture, le regard traverse les dix-neuf fenêtres jusqu’aux cerfs, et les tranches du carton découpé entourent le tunnel comme les troncs eux-mêmes. Au dos de chaque feuillet, un vers nomme le plan d’en face. Le PDF pour l’imprimeur porte toutes les fenêtres sur la plaque de découpe.

Cette recette répond à

  • Comment faire un livre tunnel dont les trous laissent voir vingt pages en profondeur ?
  • Comment fournir au fabricant de formes le tracé de découpe sur une plaque à part dans le PDF ?

La réponse courte

script.js · lignes 38–50dans le code complet
// Leaf k (pages 2k − 1 and 2k) is cut with a circle of radius R1 · Q^(k − 1) round the
// same centre: 58 mm on the cover down to 12 mm on leaf 19. Leaf 20, the clearing, is
// whole, so from the cover the eye goes through nineteen windows to the far plane.
const [CX, CY, R1, Q] = [75, 66, 58, 0.9162];
const radius = (k) => R1 * Q ** (k - 1);
const leaves = Array.from({ length: 19 }, (_, i) => i + 1);
const dieCuts = {
  shapes: leaves.map((k) => ({ id: `w${k}`, name: `${t({ en: 'Window', es: 'Ventana' })} ${k}`,
    shape: 'circle', x: mm(CX - radius(k)), y: mm(CY - radius(k)),
    width: mm(2 * radius(k)), height: mm(2 * radius(k)) })),
  pages: leaves.map((k) => ({ pages: String(2 * k - 1), die: `w${k}` })), // recto of leaf k
  corners: { radius: mm(4), edges: 'fore' },
};

Ingrédients

Typographie
Cormorant Garamond, Lora (SIL OFL 1.1)
Ressources
  • plane01.jpg
  • plane02.jpg
  • plane03.jpg
  • plane04.jpg
  • plane05.jpg
  • plane06.jpg
  • plane07.jpg
  • plane08.jpg
  • plane09.jpg
  • plane10.jpg
  • plane11.jpg
  • plane12.jpg
  • plane13.jpg
  • plane14.jpg
  • plane15.jpg
  • plane16.jpg
  • plane17.jpg
  • plane18.jpg
  • plane19.jpg
  • plane20.jpg
  • Plane 1 of the wood (Generated With Diffusion Models, original)
  • Plane 2 of the wood (Generated With Diffusion Models, original)
  • Plane 3 of the wood (Generated With Diffusion Models, original)
  • Plane 4 of the wood (Generated With Diffusion Models, original)
  • Plane 5 of the wood (Generated With Diffusion Models, original)
  • Plane 6 of the wood (Generated With Diffusion Models, original)
  • Plane 7 of the wood (Generated With Diffusion Models, original)
  • Plane 8 of the wood (Generated With Diffusion Models, original)
  • Plane 9 of the wood (Generated With Diffusion Models, original)
  • Plane 10 of the wood (Generated With Diffusion Models, original)
  • Plane 11 of the wood (Generated With Diffusion Models, original)
  • Plane 12 of the wood (Generated With Diffusion Models, original)
  • Plane 13 of the wood (Generated With Diffusion Models, original)
  • Plane 14 of the wood (Generated With Diffusion Models, original)
  • Plane 15 of the wood (Generated With Diffusion Models, original)
  • Plane 16 of the wood (Generated With Diffusion Models, original)
  • Plane 17 of the wood (Generated With Diffusion Models, original)
  • Plane 18 of the wood (Generated With Diffusion Models, original)
  • Plane 19 of the wood (Generated With Diffusion Models, original)
  • Plane 20 of the wood (Generated With Diffusion Models, original)

Préparation

#1 · Dix-neuf fenêtres sur un axe

Le code est la réponse courte plus haut. Les fenêtres sortent d’une boucle : le feuillet k reçoit un cercle de rayon R1 · Q^(k − 1) autour du même centre, et dieCuts.pages le place en page 2k − 1, le recto de ce feuillet. Un trou perce les deux faces, si bien que le verso derrière porte la même fenêtre, en miroir. Q = 0,9162 mène de 58 mm à 12 mm en dix-huit pas.

#2 · Des plans en repérage avec leurs fenêtres

script.js · lignes 54–71dans le code complet
// The plane pictures were scaled so each painting's opening meets its window, centred on
// (CX, CY), over a softened copy of itself; the window's centre is flat, the die takes it.
const SHEET = { width: mm(TRIM + 2 * BLEED), height: mm(TRIM + 2 * BLEED) };
const painting = { kind: 'image', id: 'painting', resourceId: '{attr.picture}', fit: 'cover',
  placement: at('page', 'top-left', -BLEED, -BLEED, SHEET) };
const full = (elements) => ({ enabled: true, minHeight: mm(TRIM - TOP), slot: { elements } });
const plate = { kind: 'box', id: 'plate', placement: at('page', 'top-left', 25, 129,
  { width: mm(100), height: mm(17) }), style: { backgroundColor: col('forest') } };
const line = (id, content, y, size, color, extra) => ({ kind: 'text', id, content,
  fontFamily: DISPLAY, fontSize: pt(size), lineHeight: 1.1, color: col(color),
  align: 'center', placement: at('page', 'top-left', 25, y, { width: mm(100) }), ...extra });
const headingStyles = [
  { id: 'cover', numbered: false, toc: false, advancedDesign: full([painting, plate,
    line('title', '{title}', 131, 21, 'cream', { fontWeight: 600 }),
    line('subtitle', '{subtitle}', 139.5, 10.5, 'moss', { italic: true })]) },
  { id: 'plane', numbered: false, breakBefore: { enabled: true, parity: 'odd' },
    advancedDesign: full([painting]) },
];

Chaque peinture a sa propre clairière de brume, alors les images ont été mises à l’échelle avant d’entrer dans le livre : sur chacune, on a mesuré en pixels le rayon où les feuilles couvrent la moitié de l’anneau, puis on a réduit la peinture jusqu’à ce que ce rayon rencontre la fenêtre de son feuillet. Vu de la couverture, chaque plan ne montre qu’un mince anneau de feuilles autour de sa fenêtre, et les anneaux s’empilent en tunnel. Le centre que chaque découpe emporte est uni, et ne pèse presque rien.

#3 · Dix-neuf cercles sur la plaque Die

script.js · lignes 83–84dans le code complet
  print: { standard: 'pdfx4', outputProfile: 'fogra51', convertImages: false,
    dieLine: { output: 'page', ink: 'Die', width: pt(0.5) } },

Le PDF trace chaque fenêtre, et chaque feuillet avec ses coins arrondis côté gouttière, sur une séparation Die en surimpression, jamais encrée. Quarante pages de peintures restent sous 1,5 Mo avec convertImages: false.

#4 · Le tunnel en main

script.js · lignes 99–105dans le code complet
  folio: {
    tilt: 40, yaw: -30,
    paper: { type: 'board', shade: '#f4ecd6' },
    binding: { type: 'hardcover', cover: 'pages', coverMaterial: 'paper' },
    surface: { type: 'oak' },
    lighting: { environment: 'daylight', intensity: 1.1 },
  },

Vingt feuillets de carton font un bloc épais, et Folio y découpe chaque fenêtre : le livre fermé montre le tunnel, les parois de la découpe descendant en gradins jusqu’à la clairière.

#5 · Vingt plans sur une page à plat

script.js · lignes 250–260dans le code complet
// `beneath` paints the page two on, which paints the page two on from it, and so on to
// the clearing: page 1 shows all twenty planes. Each canvas is painted once and reused.
const under = new Map();
const beneath = (i) => {
  if (!under.has(i) && doc.pages[i]) {
    const canvas = document.createElement('canvas');
    under.set(i, canvas);
    renderPageToCanvas(doc.pages[i], doc, canvas, { scale: 1, beneath });
  }
  return under.get(i);
};

beneath peint la page deux plus loin avec son propre beneath : la fenêtre de la couverture montre la page 3, dont la fenêtre montre la 5, et ainsi jusqu’à la 39. Chaque page est peinte une fois puis réutilisée.

La recette complète

Sandbox
// ═══ Postext Cookbook · Nº 195 · A tunnel book twenty leaves deep ═══════════════════════
// https://postext.dev/en/cookbook/forest-tunnel-book
// Code: MIT · Text: original (CC BY 4.0) · Paintings: generated with diffusion models
// Fonts: Cormorant Garamond, Lora (SIL OFL 1.1) · Needs postext ≥ 1.84.0
//
// Twenty board leaves, each printed with one plane of a wood and cut with a round window a
// little smaller than the one before. From the cover you look down the whole tunnel, past
// oaks, foxgloves, an owl and a fox, to a doe and her fawn at a pool in the clearing.
import {
  buildDocumentWithFonts, renderPageToCanvas, registerResourceImage,
} from 'https://esm.sh/postext';
import { renderToPdf, decompressWoff2 } from 'https://esm.sh/postext-pdf';
import { createFolioFromDocument } from 'https://esm.sh/postext-folio';

const LANG = 'en'; // @lang: the language of the sample document ('en' | 'es')
const RECIPE = 'forest-tunnel-book';

// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: a deep forest green behind the words, cream type
const palette = {
  forest: '#1c2a1e', // the versos, and the plate under the cover title
  cream: '#f4ecd6', // all the type
  moss: '#a9b98a', // the subtitle and the colophon
};
const col = (id) => ({ hex: palette[id], model: 'hex', paletteId: id });
const colorPalette = [
  ...Object.entries(palette).map(([id, hex]) => ({ id, name: id, value: { hex, model: 'hex' } })),
  { id: 'main-color', name: 'moss (defaults)', value: { hex: palette.moss, model: 'hex' } },
];
// #endregion
const [TRIM, BLEED] = [150, 3]; // mm: a square board book, and its bleed
const [TOP, SIDE] = [128, 14]; // the words on each verso sit under its window
const [DISPLAY, TEXT] = ['Cormorant Garamond', 'Lora'];
const at = (to, edge, x = 0, y = 0, size) => ({ anchor: { to, edge },
  offset: { x: mm(x), y: mm(y) }, ...(size && { size }) });

// #region answer: nineteen windows, each smaller than the last, all on one axis
// Leaf k (pages 2k − 1 and 2k) is cut with a circle of radius R1 · Q^(k − 1) round the
// same centre: 58 mm on the cover down to 12 mm on leaf 19. Leaf 20, the clearing, is
// whole, so from the cover the eye goes through nineteen windows to the far plane.
const [CX, CY, R1, Q] = [75, 66, 58, 0.9162];
const radius = (k) => R1 * Q ** (k - 1);
const leaves = Array.from({ length: 19 }, (_, i) => i + 1);
const dieCuts = {
  shapes: leaves.map((k) => ({ id: `w${k}`, name: `${t({ en: 'Window', es: 'Ventana' })} ${k}`,
    shape: 'circle', x: mm(CX - radius(k)), y: mm(CY - radius(k)),
    width: mm(2 * radius(k)), height: mm(2 * radius(k)) })),
  pages: leaves.map((k) => ({ pages: String(2 * k - 1), die: `w${k}` })), // recto of leaf k

Le script.js composé s’exécute tel quel : collez-le dans le script de module de n’importe quelle page, ou ouvrez la recette sur CodePen. Dossier de la recette sur GitHub ↗ (s’ouvre dans un nouvel onglet)

Variantes

#Des fenêtres carrées aux coins arrondis

Un roundRect au rayon d’angle égal au tiers de sa demi-largeur donne un air plus doux, de papier découpé.

-    shape: 'circle', x: mm(CX - radius(k)), y: mm(CY - radius(k)),
+    shape: 'roundRect', radius: mm(radius(k) / 3), x: mm(CX - radius(k)), y: mm(CY - radius(k)),

#Arrondir tous les coins

Un livre cartonné pour petites mains arrondit les quatre coins de chaque feuillet.

-  corners: { radius: mm(4), edges: 'fore' },
+  corners: { radius: mm(8), edges: 'all' },

Crédits

Texte
  • The verse of the walk and the colophon · Postext Cookbook · CC BY 4.0
Images
  • Plane 1 of the wood · Generated With Diffusion Models · original
  • Plane 2 of the wood · Generated With Diffusion Models · original
  • Plane 3 of the wood · Generated With Diffusion Models · original
  • Plane 4 of the wood · Generated With Diffusion Models · original
  • Plane 5 of the wood · Generated With Diffusion Models · original
  • Plane 6 of the wood · Generated With Diffusion Models · original
  • Plane 7 of the wood · Generated With Diffusion Models · original
  • Plane 8 of the wood · Generated With Diffusion Models · original
  • Plane 9 of the wood · Generated With Diffusion Models · original
  • Plane 10 of the wood · Generated With Diffusion Models · original
  • Plane 11 of the wood · Generated With Diffusion Models · original
  • Plane 12 of the wood · Generated With Diffusion Models · original
  • Plane 13 of the wood · Generated With Diffusion Models · original
  • Plane 14 of the wood · Generated With Diffusion Models · original
  • Plane 15 of the wood · Generated With Diffusion Models · original
  • Plane 16 of the wood · Generated With Diffusion Models · original
  • Plane 17 of the wood · Generated With Diffusion Models · original
  • Plane 18 of the wood · Generated With Diffusion Models · original
  • Plane 19 of the wood · Generated With Diffusion Models · original
  • Plane 20 of the wood · Generated With Diffusion Models · original
Polices
Cormorant Garamond (SIL OFL 1.1) · Lora (SIL OFL 1.1)
SandboxPDF