Saltar al contingut principal
Recepta número 195

Receptari · Capítol 10 · Sortida i integració

Un llibre túnel de vint fulls de fondària

Dinou finestres rodones troquelades amb dieCuts, cadascuna més petita que l’anterior: des de la coberta es veu a través de vint plans fins a un cérvol.

En aquesta pàgina
Nivell
Avançat
Postext
Provada amb Postext 1.84.0
Requereix ≥ 1.84.0 · postext-pdf ≥ 1.84.0
Llicència
Actualitzada el 13 de nov. del 2026
Codi MIT · Text CC BY 4.0
  • Mostra en castellà: encara no hi ha edició en català
  • Format 150 × 150 mm
  • 1 columna
  • Cormorant Garamond 14/17
  • Lora
  • 40 pàgines
  • Nivell
  • Postext 1.84.0
  • Compost en 6 ms
  • 166 línies de codi

En poques paraules

Un llibre gruixut de cartró sobre un passeig pel bosc. Cada full té un forat rodó una mica més petit que l’anterior, i des de la coberta es veu fins a l’última pàgina.

Què compondràs

Al fons del bosc, un llibre túnel de vint fulls de cartró en un quadrat de 150 mm. Cada recto és un pla d’un bosc pintat (roures, didaleres, un pit-roig, una guineu entre les falgueres, un mussol, bedolls), i cadascun porta una finestra rodona una mica més petita que l’anterior, totes amb el mateix centre. L’últim pla és sencer: una cérvola i el seu cervatell en una bassa de la clariana. Des de la coberta, la vista travessa les dinou finestres fins als cérvols, i els cantells del cartró tallat envolten el túnel com els mateixos troncs. Al dors de cada full, un vers anomena el pla que té al davant. El PDF d’impremta porta totes les finestres a la planxa de troquel.

Aquesta recepta respon a

  • Com faig un llibre túnel els forats del qual deixin veure vint pàgines de fons?
  • Com lliuro al troquelista la línia de troquel en una planxa pròpia del PDF?

La resposta curta

script.js · línies 38–50al codi 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' },
};

Ingredients

Tipografia
Cormorant Garamond, Lora (SIL OFL 1.1)
Recursos
  • 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)

Elaboració

#1 · Dinou finestres sobre un eix

El codi és la resposta curta de dalt. Les finestres surten d’un bucle: el full k porta un cercle de radi R1 · Q^(k − 1) al voltant del mateix centre, i dieCuts.pages el posa a la pàgina 2k − 1, el recto d’aquell full. Un forat talla les dues cares del full, i el vers de darrere té la mateixa finestra, en mirall. Q = 0,9162 porta de 58 mm a 12 mm en divuit passos.

#2 · Plans en registre amb les finestres

script.js · línies 54–71al codi 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]) },
];

Cada pintura té la seva pròpia clariana de boira, i les imatges es van escalar abans d’entrar al llibre: a cadascuna es va mesurar en píxels el radi on les fulles cobreixen la meitat de l’anell, i es va escalar la pintura fins que aquest radi coincidís amb la finestra del seu full. Des de la coberta, cada pla ensenya només un anell fi de fulles al voltant de la finestra, i els anells s’apilen en un túnel. El centre que s’endú cada troquel és pla, i gairebé no pesa al fitxer.

#3 · Dinou cercles a la planxa Die

script.js · línies 83–84al codi complet
  print: { standard: 'pdfx4', outputProfile: 'fogra51', convertImages: false,
    dieLine: { output: 'page', ink: 'Die', width: pt(0.5) } },

El PDF traça cada finestra, i cada full amb les cantonades arrodonides del costat del tall, en una separació Die en sobreimpressió que mai no s’entinta. Quaranta pàgines de pintures queden per sota d’1,5 MB amb convertImages: false.

#4 · El túnel a la mà

script.js · línies 99–105al codi 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 },
  },

Vint fulls de cartró fan un bloc gruixut, i Folio troquela cada finestra a través seu: el llibre tancat ensenya el túnel, amb les parets del tall baixant en graons fins a la clariana.

#5 · Vint plans en una pàgina plana

script.js · línies 250–260al codi 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 pinta la pàgina dues més enllà amb el seu propi beneath: la finestra de la coberta ensenya la pàgina 3, la finestra de la qual ensenya la 5, i així fins a la 39. Cada pàgina es pinta una vegada i es reutilitza.

La recepta completa

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 = 'es'; // @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

L'script.js compost funciona tal com és: enganxa'l com a script de mòdul en qualsevol pàgina o obre la recepta a CodePen. Carpeta de la recepta a GitHub ↗ (s'obre en una pestanya nova)

Variants

#Finestres quadrades de cantonades rodones

Un roundRect amb un radi de cantonada d’un terç del seu semiample dona un aire més suau, de paper retallat.

-    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)),

#Arrodoneix totes les cantonades

Un llibre de cartró per a mans petites arrodoneix les quatre cantonades de cada full.

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

Crèdits

Text
  • The verse of the walk and the colophon · Postext Cookbook · CC BY 4.0
Imatges
  • 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
Fonts
Cormorant Garamond (SIL OFL 1.1) · Lora (SIL OFL 1.1)
SandboxPDF