Saltar al contingut principal
Recepta número 136

Receptari · Capítol 10 · Sortida i integració

Un diari viu amb fotos que es mouen

Sis recursos de vídeo compostos com a fotos de premsa en un tabloide a quatre columnes; autoplay, loop i exclusive: false els reprodueixen alhora a Folio.

  • Mostra en anglès: encara no hi ha edició en català
  • Format 280 × 430 mm
  • 4 columnes, espai entre columnes de 4,5 mm
  • Libre Caslon Text 8,8/11,6
  • Courier Prime
  • Oswald
  • 4 pàgines
  • Nivell
  • Postext 1.57.1
  • Compost en 202 ms
  • 250 línies de codi

En poques paraules

Un diari local a l'estil dels anys trenta en què cada foto és una pel·lícula muda i curta. En paper són imatges fixes; al visor 3D es mouen totes alhora, una vegada i una altra, com un diari de conte.

Què compondràs

The Wexcombe Lantern, un setmanari costaner inventat de juny de 1933, en una pàgina tabloide de 280 × 430 mm a quatre columnes amb filet: una capçalera estreta, una notícia principal amb la seva foto a tres columnes, una altra a dues, taules de marees, anuncis per paraules i una pàgina d'esports. Cada foto és una pel·lícula de cinc segons en blanc i negre. A l'imprès, i a les pàgines planes sota el visor, cadascuna és el seu primer fotograma. Quan s'obre a Folio com un diari doblegat, sobre paper premsa clar, les fotos de les pàgines obertes es mouen alhora i no s'aturen: l'alcaldessa parla, l'aviadora saluda, el pescador riu, el porter es llança i es torna a aixecar. La pàgina no dibuixa res; la maquetació és la d'un diari corrent i els clips fan la resta.

Aquesta recepta respon a

  • Com faig que diversos vídeos curts sense so es reprodueixin alhora en una pàgina i tornin a començar cada cop que s'hi passa?
  • Com mostro un diari al visor 3D com a plecs doblegats, amb les pàgines d'economia en paper salmó?

La resposta curta

script.js · línies 47–61al codi complet
// A video resource prints its poster (the first frame) on the flat page. In Folio, and in the
// HTML viewer, the poster comes alive: autoplay starts it muted when its page is on show, loop
// keeps it going, and exclusive: false lets it run alongside the other clips instead of
// pausing them, as one exclusive player at a time would.
const videoStyle = {
  playMark: { enabled: false }, // a press photograph, not a play button
  qr: { enabled: false }, // the clips live on the page, not behind a link
  linkPoster: false,
  player: { autoplay: true, loop: true, muted: true, exclusive: false, controls: false },
};
const clip = (id, url, [w, h], placement, caption, altText) => ({ id, typeId: 'picture',
  kind: 'video', createdAt: 0, updatedAt: 0, caption, altText, placement,
  video: { source: 'file', fileId: `${id}-loop.mp4`, url, // url: where the clip plays from
    format: 'mp4', width: w, height: h, duration: 5,
    poster: { fileId: `${id}-poster.jpg`, format: 'jpeg', width: w, height: h } } });

Ingredients

Tipografia
Libre Caslon Text, Oswald, Courier Prime (SIL OFL 1.1)
Recursos
  • actress-loop.mp4
  • actress-poster.jpg
  • aviator-loop.mp4
  • aviator-poster.jpg
  • clock-loop.mp4
  • clock-poster.jpg
  • fisherman-loop.mp4
  • fisherman-poster.jpg
  • keeper-loop.mp4
  • keeper-poster.jpg
  • mayor-loop.mp4
  • mayor-poster.jpg
  • Mrs Edith Rowe speaks at the opening of the Harbour line: a black-and-white loop of 5 s, a still generated from a text prompt and animated with the same first and last frame, encoded with ffmpeg (Generated With Diffusion Models, CC BY 4.0)
  • The first frame of the mayor loop, its printed picture (Generated With Diffusion Models, CC BY 4.0)
  • The Guildhall clock tower: a black-and-white loop of 5 s, a still generated from a text prompt and animated with the same first and last frame, encoded with ffmpeg (Generated With Diffusion Models, CC BY 4.0)
  • The first frame of the clock loop, its printed picture (Generated With Diffusion Models, CC BY 4.0)
  • Skipper Jacob Hosking with the cod: a black-and-white loop of 5 s, a still generated from a text prompt and animated with the same first and last frame, encoded with ffmpeg (Generated With Diffusion Models, CC BY 4.0)
  • The first frame of the fisherman loop, its printed picture (Generated With Diffusion Models, CC BY 4.0)
  • Miss Constance Lacey in the cockpit: a black-and-white loop of 5 s, a still generated from a text prompt and animated with the same first and last frame, encoded with ffmpeg (Generated With Diffusion Models, CC BY 4.0)
  • The first frame of the aviator loop, its printed picture (Generated With Diffusion Models, CC BY 4.0)
  • Miss Rosalind Avery on the stage: a black-and-white loop of 5 s, a still generated from a text prompt and animated with the same first and last frame, encoded with ffmpeg (Generated With Diffusion Models, CC BY 4.0)
  • The first frame of the actress loop, its printed picture (Generated With Diffusion Models, CC BY 4.0)
  • Tom Rundle in goal: a black-and-white loop of 5 s, a still generated from a text prompt and animated with the same first and last frame, encoded with ffmpeg (Generated With Diffusion Models, CC BY 4.0)
  • The first frame of the keeper loop, its printed picture (Generated With Diffusion Models, CC BY 4.0)

Elaboració

#1 · Fes de cada foto un clip que es repeteix amb els altres

El codi és la resposta curta de dalt. Un recurs de vídeo imprimeix la seva portada com una imatge, així que els clips ocupen el lloc de les fotografies i porten peu com elles. Tres opcions del reproductor donen vida a la pàgina: autoplay engega un clip quan la seva pàgina és a la vista (sempre sense so, com exigeixen els navegadors), loop el torna a reproduir des del principi i exclusive: false deixa que corri al costat dels altres clips. Per defecte un vídeo és exclusiu: quan s'engega, posa en pausa tot el que s'estigui reproduint, cosa que serveix per a una classe però no per a una pàgina de fotos en moviment. La marca de reproducció i el codi QR estan desactivats, de manera que en paper els clips es llegeixen com a fotos de premsa.

#2 · Dona a cada bucle el seu lloc a la retícula

script.js · línies 65–91al codi complet
const resources = [
  clip('mayor', asset('mayor-loop.mp4'), [640, 480],
    { position: 'top', span: 'column', columns: 3 },
    '**Mrs Edith Rowe** speaks from the platform at the foot of Quay Hill before cutting '
      + 'the ribbon.',
    'A woman in a dark coat and small hat speaks at a draped podium, one hand raised.'),
  clip('clock', asset('clock-loop.mp4'), [480, 640],
    { position: 'top', span: 'column', columns: 2 },
    '**Twelve o’clock** on the Guildhall tower, for the first time since 1924.',
    'A stone clock tower against clouds, pigeons on its ledge.'),
  clip('fisherman', asset('fisherman-loop.mp4'), [640, 480],
    { position: 'auto', span: 'column', columns: 2 },
    '**Skipper Jacob Hosking** and the 82-pound cod on the quay.',
    'An old fisherman in an oilskin laughs, holding up a huge cod.'),
  clip('aviator', asset('aviator-loop.mp4'), [640, 480],
    { position: 'top', span: 'column', columns: 2 },
    '**Miss Constance Lacey** waves from the cockpit on Wexcombe Common.',
    'A young woman in a flying helmet waves from the open cockpit of a biplane.'),
  clip('actress', asset('actress-loop.mp4'), [480, 640],
    { position: 'top', span: 'column', columns: 2 },
    '**Miss Rosalind Avery** as Hester Lane, on the garden steps in Act III.',
    'An actress in a long gown on a garden stage set, one arm outstretched.'),
  clip('keeper', asset('keeper-loop.mp4'), [640, 480],
    { position: 'top', span: 'column', columns: 3 },
    '**Tom Rundle** at Gannet Park, before the penalty he saved.',
    'A goalkeeper in a flat cap crouches on his line in front of a packed terrace.'),
];

La maquetació és layoutType: 'multiple' amb columnCount: 4. El columns d'un flotant fixa quantes n'ocupa: els clips de l'alcaldessa i del porter, tres; els de l'aviadora, la torre del rellotge, el pescador i l'actriu, dues. Un flotant a diverses columnes ocupa el capdamunt d'una sèrie de columnes buides que comencen a la mateixa altura, o el peu de la columna on es cita i de les buides que la segueixen, així que el lloc de la línia ::resource decideix el buit. L'alcaldessa es cita després del primer paràgraf, cosa que deixa la columna 1 al text i posa la foto sobre les columnes 2 a 4.

#3 · Compon la capçalera i les pàgines de secció

script.js · línies 131–147al codi complet
const nameplate = { enabled: true, slot: { elements: [
  depth(10), // the masthead is ten grid lines deep; the rules and the dateline hang from it
  { kind: 'rule', id: 'foot', thickness: pt(2.5), color: col('ink'),
    placement: { ...at('#depth', 'align-bottom', 0, -1.5), size: { width: 'fill' } } },
  ...[['left', '{attr.issue}'], ['center', '{publishDate}'], ['right', '{attr.price}']].map(
    ([align, content]) => text(`date-${align}`, content, { ...typed(9, { fontWeight: 700 }),
      align }, { ...at('#foot', 'above', 0, -1.6), size: { width: 'fill' } })),
  rule('thin', '#date-left', 0.6, 1.8),
  text('name', '{titleText}', { ...oswald(66, 700, { textTransform: 'uppercase',
    letterSpacing: pt(1.5) }), lineHeight: 1, align: 'center' },
  { ...at('#thin', 'above', 0, -2), size: { width: 'fill' } }),
  // Two ears over the name: the paper's age on the left, the weather on the right.
  text('since', '{attr.since}', { ...caps(8, 600, 'flag'), align: 'left' },
    { ...at('container', 'top-left', 0, 1), size: { width: mm(90) } }),
  text('weather', 'Weather: {attr.weather}', { ...typed(8.5, { italic: true }), align: 'right' },
    { ...at('container', 'top-right', 0, 1), size: { width: mm(110) } }),
] } };

El títol de nivell 1 de la portada és el nom del diari, compost en una zona de disseny: dues orelles a sobre, el nom en majúscules d'Oswald i una línia de data entre un filet fi i un de gruixut. Les pàgines interiors obren amb un rètol vermell de secció sobre una barra de 3 pt (la regió pages), i totes les pàgines menys la primera porten una línia de foli al capdamunt.

#4 · Obre el diari a Folio

script.js · línies 572–581al codi complet
const stage = Object.assign(document.createElement('section'),
  { id: 'folio', ariaLabel: 'The newspaper in 3D' });
stage.style.cssText = 'height: min(82vh, 820px); margin: 0 auto; max-width: 1280px';
document.getElementById('pages').before(stage);
createFolioFromDocument(stage, doc, {
  // Folio plays each clip from its video.url, muted, while its page is on show.
  appearance: { textureBaseUrl: 'https://postext.dev/folio/textures' },
  onChange: ({ pages }) => kitStatus(`${doc.pages.length} pages · open at `
    + pages.map((i) => doc.pages[i].pageLabel || i + 1).join('–')),
});

config.folio posa el diari sobre roure amb llum de dia: paper premsa de 45 g/m², que deixa veure per transparència la pàgina següent, i binding.type: 'folded', plecs doblegats una vegada i posats l'un dins de l'altre, sense grapes ni llom, com es munta un diari. Folio dibuixa tots els clips de la doble pàgina oberta en una sola textura, fins a vuit alhora, engega els bucles automàtics cada vegada que un pas de pàgina s'atura a la seva i els atura quan aquesta pàgina es passa. Un clic en un vídeo exclusiu el continua reproduint tot sol, amb el seu so, i els bucles esperen que s'acabi.

La recepta completa

Sandbox
// ═══ Postext Cookbook · Nº 136 · A living newspaper of video loops ══════════════
// https://postext.dev/en/cookbook/living-newspaper-video-loops
// Code: MIT · Text: original (CC BY 4.0) · Clips: generated with diffusion models (CC BY 4.0)
// Fonts: Oswald, Libre Caslon Text, Courier Prime (SIL OFL 1.1) · Needs postext ≥ 1.28.0
import {
  buildDocumentWithFonts, renderPageToCanvas, registerResourceImage,
} from 'https://esm.sh/postext';
import { createFolioFromDocument } from 'https://esm.sh/postext-folio';

const LANG = 'en'; // @lang: the language of the sample document ('en')
const RECIPE = 'living-newspaper-video-loops';

// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: newsprint, a warm black and a dark red for the flags
const palette = {
  ink: '#16130f', // text, rules and the nameplate
  paper: '#f3efe4', // newsprint, and type reversed out of ink or red
  flag: '#8e1b14', // the one accent: section flags, kickers, the jump lines
  tint: '#e6dfcf', // the In brief strip
  rule: '#8f897c', // hairlines: the column rules
  muted: '#5b554b', // bylines, captions' credits, the imprint
};
const col = (id) => ({ hex: palette[id], model: 'hex', paletteId: id });
const colorPalette = [ // defaults link to 'main-color': point it at the ink, never blue
  ...Object.entries(palette).map(([id, hex]) => ({ id, name: id, value: { hex, model: 'hex' } })),
  { id: 'main-color', name: 'ink (defaults)', value: { hex: palette.ink, model: 'hex' } },
];
// #endregion
const MARGIN = { top: 12, bottom: 12, side: 12 }; // mm: a tabloid's narrow margins
const GUTTER = 4.5; // mm between the four columns
const LEAD = 11.6; // body leading in pt: the baseline grid
const oswald = (size, weight, look = {}) => ({ fontFamily: 'Oswald', fontSize: pt(size),
  fontWeight: weight, color: col('ink'), ...look });
const caps = (size, weight, colour = 'ink') => oswald(size, weight, { color: col(colour),
  textTransform: 'uppercase', letterSpacing: pt(size * 0.12) });
const typed = (size, look = {}) => ({ fontFamily: 'Courier Prime', fontSize: pt(size),
  color: col('ink'), ...look }); // the dateline and the captions: a typewriter
const at = (to, edge, x = 0, y = 0) => ({ anchor: { to, edge }, offset: { x: mm(x), y: mm(y) } });
const text = (id, content, look, placement) => ({ kind: 'text', id, content, align: 'left',
  overflow: 'wrap', color: col('ink'), ...look, placement }); // wraps, in a running head too
const rule = (id, under, weight, gap = 0) => ({ kind: 'rule', id, thickness: pt(weight),
  color: col('ink'), placement: { ...at(under, 'above', 0, -gap), size: { width: 'fill' } } });
const depth = (lines) => ({ kind: 'box', id: 'depth', style: {}, placement: {
  ...at('container', 'top-left'), size: { width: 'fill', height: pt(lines * LEAD) } } });

// #region answer: every picture is a clip that loops, autoplays and plays with the others
// A video resource prints its poster (the first frame) on the flat page. In Folio, and in the
// HTML viewer, the poster comes alive: autoplay starts it muted when its page is on show, loop

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

#Deixa que el lector engegui cada clip

Sense autoplay, les fotos es queden quietes fins que el lector fa clic en una; un cop engegats, els bucles es reprodueixen junts igualment.

-  player: { autoplay: true, loop: true, muted: true, exclusive: false, controls: false },
+  player: { loop: true, muted: true, exclusive: false, controls: false },

#Un clip exclusiu amb el seu so

Un vídeo es pot quedar amb el valor per defecte i reproduir-se pel seu compte: posa player: { exclusive: true, muted: false } al video d'aquest recurs, i quan s'engega els bucles esperen fins que s'acaba.

#Un diari de gran format a sis columnes

La portada a dues columnes compon un diari més petit amb fotos fixes; la mateixa retícula admet sis columnes en un format llençol amb sizePreset: 'broadsheet'.

Errors freqüents

Una secció de diari és un títol de nivell 1 que obre pàgina, i un flotant no el travessa mai. Una foto que no troba buit a l'última pàgina de la seva secció es col·loca en una pàgina pròpia abans de la secció següent, així que ajusta el text a la pàgina: aquí la notícia dels tramvies salta a la pàgina 2 en lloc de fer fora l'aviadora de la portada.

Crèdits

Text
Text original, CC BY 4.0
Imatges
  • Mrs Edith Rowe speaks at the opening of the Harbour line: a black-and-white loop of 5 s, a still generated from a text prompt and animated with the same first and last frame, encoded with ffmpeg · Generated With Diffusion Models · CC BY 4.0
  • The first frame of the mayor loop, its printed picture · Generated With Diffusion Models · CC BY 4.0
  • The Guildhall clock tower: a black-and-white loop of 5 s, a still generated from a text prompt and animated with the same first and last frame, encoded with ffmpeg · Generated With Diffusion Models · CC BY 4.0
  • The first frame of the clock loop, its printed picture · Generated With Diffusion Models · CC BY 4.0
  • Skipper Jacob Hosking with the cod: a black-and-white loop of 5 s, a still generated from a text prompt and animated with the same first and last frame, encoded with ffmpeg · Generated With Diffusion Models · CC BY 4.0
  • The first frame of the fisherman loop, its printed picture · Generated With Diffusion Models · CC BY 4.0
  • Miss Constance Lacey in the cockpit: a black-and-white loop of 5 s, a still generated from a text prompt and animated with the same first and last frame, encoded with ffmpeg · Generated With Diffusion Models · CC BY 4.0
  • The first frame of the aviator loop, its printed picture · Generated With Diffusion Models · CC BY 4.0
  • Miss Rosalind Avery on the stage: a black-and-white loop of 5 s, a still generated from a text prompt and animated with the same first and last frame, encoded with ffmpeg · Generated With Diffusion Models · CC BY 4.0
  • The first frame of the actress loop, its printed picture · Generated With Diffusion Models · CC BY 4.0
  • Tom Rundle in goal: a black-and-white loop of 5 s, a still generated from a text prompt and animated with the same first and last frame, encoded with ffmpeg · Generated With Diffusion Models · CC BY 4.0
  • The first frame of the keeper loop, its printed picture · Generated With Diffusion Models · CC BY 4.0
Fonts
Libre Caslon Text (SIL OFL 1.1) · Oswald (SIL OFL 1.1) · Courier Prime (SIL OFL 1.1)
Sandbox