mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-23 13:23:04 +00:00
5651c11803
- design_book takes a brief (energy, decoration, collages, theme), a cover archetype and a cover lockup, and pages.overrides that give single pages of the plan another beat or layout. Directives written before parse as they did, and a design asked for none of it is composed exactly as before. - The engine composes the seven cover archetypes from the book's own photos, words, theme faces and colours, lockups, shapes and stickers, varied by the seed: spine band, poster pop, cut-out, illustrated postcard, grid and badge, minimal serif and stamp collage. A title the directives give a display tier is held to it, and the notes say when a band, a badge or a stamp holds it smaller or a cover leaves a layout out. - A lively or loud book turns two in five hero and grid spreads into collages, script overlays, badge grids, stamp rows or two-tone splits, the first of them always, turns and frames the prints of its other pages, sets its cover title larger and takes one or two, or three to six, stickers of its theme's motifs a spread, never over words, a photo's detail or the fold. A calm book asked for collages gets them and nothing else. - Every turn the engine gives a print or a sticker stays within what the brief's energy takes, a calm book's within its theme's own, so a design is never judged against its own brief. - New checks name a flat cover, a page without a lead, colours or faces off the theme and, for a design made with a brief, a book livelier or calmer than it asked, on the pages the design made and on a page revised in the draft. Page edits answer with the art checks too, and the assistant's cards name them in every language. - list_book_assets lists the shapes, faces, lockups, themes and patterns beside the stickers, and the Studio's shape groups and photo frames are one list the assistant reads too. - The Studio prompt gains an index of themes, archetypes and faces and JSON recipes of the elements to add and style for each cover and three lively spreads, and a turn that designs the book may preview sixteen pages, still three images a request; a viewer is told of none of it.
66 lines
2.3 KiB
TypeScript
66 lines
2.3 KiB
TypeScript
/**
|
|
* The design engine's seeded variation: which edge a band sits on, how far a
|
|
* print is turned, which sticker a page takes. Never random: the same seed and
|
|
* the same key give the same numbers on every run and on every machine, so a
|
|
* design is reproducible and another `seed` gives another, equally valid one.
|
|
*
|
|
* FNV-1a over the seed and a key that names the decision, then mulberry32. Not
|
|
* for anything that has to be unpredictable: it only spreads choices evenly.
|
|
*/
|
|
|
|
export interface DesignRng {
|
|
/** The next number in [0, 1). */
|
|
next(): number;
|
|
/** A number in [lo, hi). */
|
|
range(lo: number, hi: number): number;
|
|
/** A whole number from lo to hi, both included. */
|
|
int(lo: number, hi: number): number;
|
|
/** One item of a list, or undefined for an empty one. */
|
|
pick<T>(list: readonly T[]): T | undefined;
|
|
/** The list in a shuffled order, the list itself left as it is. */
|
|
shuffle<T>(list: readonly T[]): T[];
|
|
/** True with probability p. */
|
|
chance(p: number): boolean;
|
|
/** 1 or -1. */
|
|
sign(): 1 | -1;
|
|
}
|
|
|
|
function hash(seed: number, key: string): number {
|
|
let h = (2166136261 ^ seed) >>> 0;
|
|
for (let i = 0; i < key.length; i++) {
|
|
h ^= key.charCodeAt(i);
|
|
h = Math.imul(h, 16777619) >>> 0;
|
|
}
|
|
return h;
|
|
}
|
|
|
|
/** The numbers of one decision of a design, from its seed and a key naming the decision. */
|
|
export function designRng(seed: number, key: string): DesignRng {
|
|
let state = hash(seed, key);
|
|
const next = () => {
|
|
state = (state + 0x6d2b79f5) | 0;
|
|
let t = Math.imul(state ^ (state >>> 15), 1 | state);
|
|
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
|
|
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
|
};
|
|
const rng: DesignRng = {
|
|
next,
|
|
range: (lo, hi) => lo + (hi - lo) * next(),
|
|
int: (lo, hi) => lo + Math.floor(next() * (hi - lo + 1)),
|
|
pick: (list) => (list.length ? list[Math.floor(next() * list.length)] : undefined),
|
|
shuffle: (list) => {
|
|
const out = [...list];
|
|
for (let i = out.length - 1; i > 0; i--) {
|
|
const j = Math.floor(next() * (i + 1));
|
|
const held = out[i] as (typeof out)[number];
|
|
out[i] = out[j] as (typeof out)[number];
|
|
out[j] = held;
|
|
}
|
|
return out;
|
|
},
|
|
chance: (p) => next() < p,
|
|
sign: () => (next() < 0.5 ? -1 : 1),
|
|
};
|
|
return rng;
|
|
}
|