[art-prep] ArtBoard: Build prompts, stand-ins and the art board from the manifest, and accept pictures into art/final
tools/art-prep reads art/STYLE.md (draft) and art/manifest.json (25 Phase 1 pictures), refuses forbidden words in any prompt, writes 29 stand-ins and the board files, and cuts and encodes accepted pictures as WebP within budget.
This commit is contained in:
@@ -0,0 +1,217 @@
|
||||
/**
|
||||
* Claude's stand-ins (CLAUDE.md §2, art/placeholders/): plain SVG shapes that test form and
|
||||
* layout until a real picture is accepted. They are deliberately simple. A stand-in that
|
||||
* looked finished would hide that the real picture is still missing.
|
||||
*/
|
||||
import type { Asset, Manifest } from './manifest.js';
|
||||
import { cellBoxes, cellSize } from './prompt.js';
|
||||
|
||||
const C = {
|
||||
rose: '#c85a6e',
|
||||
petal: '#f2b5be',
|
||||
blush: '#e8899b',
|
||||
leaf: '#7fa07a',
|
||||
moss: '#4f6e52',
|
||||
ink: '#3a2730',
|
||||
paper: '#fbf6f1',
|
||||
soil: '#8a6248',
|
||||
wood: '#b98a5a',
|
||||
meadow: '#a9c48e',
|
||||
amber: '#f2b860',
|
||||
coral: '#e9846a',
|
||||
night: '#2e3561',
|
||||
lamp: '#f4d58d'
|
||||
} as const;
|
||||
|
||||
type Eyes = 'open' | 'half' | 'closed' | 'down' | 'squeeze';
|
||||
type Mouth = 'smile' | 'small' | 'open' | 'puff';
|
||||
|
||||
interface RoseLook {
|
||||
readonly stage: 'bud' | 'opening' | 'half' | 'full';
|
||||
readonly eyes: Eyes;
|
||||
readonly mouth: Mouth;
|
||||
readonly blush?: boolean;
|
||||
/** Degrees the bloom leans from the stem top; negative is left. */
|
||||
readonly tilt?: number;
|
||||
readonly leaves?: 'normal' | 'down' | 'up' | 'raised';
|
||||
readonly back?: boolean;
|
||||
readonly drops?: boolean;
|
||||
readonly bend?: number;
|
||||
}
|
||||
|
||||
/** The rose in a 200 × 520 box: bloom near the top, stem down to the bottom edge. */
|
||||
function rose(look: RoseLook): string {
|
||||
const r = { bud: 30, opening: 44, half: 58, full: 74 }[look.stage];
|
||||
const bend = look.bend ?? 0;
|
||||
const stem = `<path d="M100 520 Q ${100 + bend} 340 ${100 + bend * 1.6} 170" fill="none" stroke="${C.moss}" stroke-width="9" stroke-linecap="round"/>`;
|
||||
const thorns = [430, 300, 220]
|
||||
.map((y, i) => `<path d="M${100 + (bend * (520 - y)) / 350 + (i % 2 ? 4 : -4)} ${y} l${i % 2 ? 12 : -12} -6 l${i % 2 ? -10 : 10} -6z" fill="${C.moss}"/>`)
|
||||
.join('');
|
||||
const leafRot = { normal: [-35, 35, -30], down: [10, -10, 15], up: [-60, 60, -55], raised: [-35, 80, -30] }[look.leaves ?? 'normal'];
|
||||
const leaf = (x: number, y: number, dir: number, rot: number): string =>
|
||||
`<ellipse cx="${x + dir * 30}" cy="${y}" rx="34" ry="14" fill="${C.leaf}" stroke="${C.ink}" stroke-width="3" transform="rotate(${rot} ${x} ${y})"/>`;
|
||||
const leaves = leaf(100, 400, -1, leafRot[0] ?? 0) + leaf(100 + bend * 0.5, 330, 1, leafRot[1] ?? 0) + leaf(100 + bend, 250, -1, leafRot[2] ?? 0);
|
||||
|
||||
const count = look.stage === 'opening' ? 5 : 8;
|
||||
const petals =
|
||||
look.stage === 'bud'
|
||||
? `<path d="M100 ${130 - r * 1.6} C ${100 + r} ${130 - r}, ${100 + r} ${130 + r * 0.6}, 100 ${130 + r * 0.7} C ${100 - r} ${130 + r * 0.6}, ${100 - r} ${130 - r}, 100 ${130 - r * 1.6}z" fill="${C.rose}" stroke="${C.ink}" stroke-width="3"/>
|
||||
<path d="M70 ${150} q30 20 60 0 l-8 18 h-44z" fill="${C.leaf}" stroke="${C.ink}" stroke-width="3"/>`
|
||||
: Array.from({ length: count }, (_, i) => {
|
||||
const a = (i / count) * Math.PI * 2;
|
||||
return `<circle cx="${(100 + Math.cos(a) * r * 0.55).toFixed(1)}" cy="${(130 + Math.sin(a) * r * 0.55).toFixed(1)}" r="${(r * 0.55).toFixed(1)}" fill="${C.rose}" stroke="${C.ink}" stroke-width="3"/>`;
|
||||
}).join('') + `<circle cx="100" cy="130" r="${(r * 0.62).toFixed(1)}" fill="${C.petal}" stroke="${C.ink}" stroke-width="3"/>`;
|
||||
|
||||
const eye = (x: number): string => {
|
||||
const y = 124;
|
||||
switch (look.eyes) {
|
||||
case 'open': return `<circle cx="${x}" cy="${y}" r="4.5" fill="${C.ink}"/>`;
|
||||
case 'half': return `<path d="M${x - 6} ${y} q6 5 12 0" fill="${C.ink}" stroke="${C.ink}" stroke-width="3"/>`;
|
||||
case 'closed': return `<path d="M${x - 6} ${y} q6 6 12 0" fill="none" stroke="${C.ink}" stroke-width="3" stroke-linecap="round"/>`;
|
||||
case 'down': return `<path d="M${x - 6} ${y + 3} q6 4 12 0" fill="none" stroke="${C.ink}" stroke-width="3" stroke-linecap="round"/>`;
|
||||
case 'squeeze': return `<path d="M${x - 6} ${y - 4} l12 4 l-12 4" fill="none" stroke="${C.ink}" stroke-width="3" stroke-linecap="round"/>`;
|
||||
}
|
||||
};
|
||||
const mouth = {
|
||||
smile: `<path d="M93 142 q7 7 14 0" fill="none" stroke="${C.ink}" stroke-width="3" stroke-linecap="round"/>`,
|
||||
small: `<path d="M96 144 h8" stroke="${C.ink}" stroke-width="3" stroke-linecap="round"/>`,
|
||||
open: `<ellipse cx="100" cy="145" rx="6" ry="5" fill="${C.ink}"/>`,
|
||||
puff: `<circle cx="100" cy="145" r="4" fill="${C.ink}"/><circle cx="84" cy="140" r="7" fill="${C.blush}" opacity=".7"/><circle cx="116" cy="140" r="7" fill="${C.blush}" opacity=".7"/>`
|
||||
}[look.mouth];
|
||||
const blush = look.blush ? `<circle cx="82" cy="138" r="8" fill="${C.blush}"/><circle cx="118" cy="138" r="8" fill="${C.blush}"/>` : '';
|
||||
const face = look.back ? '' : eye(91) + eye(109) + mouth + blush;
|
||||
const drops = look.drops
|
||||
? [[64, 92], [138, 104], [120, 70]].map(([x, y]) => `<path d="M${x} ${y} q5 9 0 12 q-5 -3 0 -12z" fill="#9cc3d8" stroke="${C.ink}" stroke-width="2"/>`).join('')
|
||||
: '';
|
||||
const bloom = `<g transform="translate(${bend * 1.6} 0) rotate(${look.tilt ?? 0} 100 170)">${petals}${face}${drops}</g>`;
|
||||
return stem + thorns + leaves + bloom;
|
||||
}
|
||||
|
||||
/** Place a drawing made in a w × h box centred in the target, filling about 76 %. */
|
||||
function fit(body: string, w: number, h: number, W: number, H: number, fill = 0.76): string {
|
||||
const s = Math.min((W * fill) / w, (H * fill) / h);
|
||||
return `<g transform="translate(${((W - w * s) / 2).toFixed(1)} ${((H - h * s) / 2).toFixed(1)}) scale(${s.toFixed(4)})">${body}</g>`;
|
||||
}
|
||||
|
||||
const ROSES: Record<string, RoseLook> = {
|
||||
'rose-bud': { stage: 'bud', eyes: 'closed', mouth: 'small' },
|
||||
'rose-opening': { stage: 'opening', eyes: 'half', mouth: 'small' },
|
||||
'rose-half-bloom': { stage: 'half', eyes: 'half', mouth: 'smile' },
|
||||
'rose-full-bloom': { stage: 'full', eyes: 'half', mouth: 'smile', tilt: -4 },
|
||||
'rose-thirsty': { stage: 'full', eyes: 'down', mouth: 'small', tilt: 14, leaves: 'down' },
|
||||
'rose-overwatered': { stage: 'full', eyes: 'squeeze', mouth: 'puff', leaves: 'down', drops: true },
|
||||
'rose-windblown': { stage: 'full', eyes: 'squeeze', mouth: 'small', bend: 22, tilt: 18, leaves: 'up' },
|
||||
'rose-blushing': { stage: 'full', eyes: 'closed', mouth: 'smile', blush: true, leaves: 'raised' },
|
||||
'rose-sleepy': { stage: 'half', eyes: 'closed', mouth: 'smile', tilt: 10 },
|
||||
'rose-speaking': { stage: 'full', eyes: 'open', mouth: 'open', leaves: 'raised' },
|
||||
'rose-waiting': { stage: 'half', eyes: 'down', mouth: 'small', tilt: -18, leaves: 'down' },
|
||||
'rose-watching-sunset': { stage: 'full', eyes: 'open', mouth: 'small', back: true, tilt: -10 }
|
||||
};
|
||||
|
||||
/** The care things, each in a 200 × 200 box. */
|
||||
const PROPS: Record<string, string> = {
|
||||
'watering-can': `<rect x="50" y="80" width="90" height="80" rx="18" fill="${C.leaf}" stroke="${C.ink}" stroke-width="5"/>
|
||||
<path d="M60 80 q35 -55 70 0" fill="none" stroke="${C.ink}" stroke-width="7"/>
|
||||
<path d="M52 110 L12 70" stroke="${C.ink}" stroke-width="10" stroke-linecap="round"/><circle cx="12" cy="68" r="10" fill="${C.leaf}" stroke="${C.ink}" stroke-width="4"/>`,
|
||||
windbreak: Array.from({ length: 9 }, (_, i) => `<path d="M${30 + i * 18} ${150 - Math.sin((i / 8) * Math.PI) * 18} v-${90 - Math.sin((i / 8) * Math.PI) * 10}" stroke="${C.wood}" stroke-width="12" stroke-linecap="round"/>`).join('')
|
||||
+ `<path d="M24 100 Q100 75 176 100" fill="none" stroke="${C.soil}" stroke-width="6"/><path d="M24 128 Q100 103 176 128" fill="none" stroke="${C.soil}" stroke-width="6"/>
|
||||
<path d="M30 150 v30 M170 150 v30" stroke="${C.soil}" stroke-width="8" stroke-linecap="round"/>`,
|
||||
'weed-clump': [60, 100, 140].map((x, i) => `<path d="M${x} 140 l-18 -${60 + i * 12} l14 12 l4 -${30 + i * 6} l8 24 l12 -20 l-6 ${60 + i * 8}z" fill="${C.leaf}" stroke="${C.ink}" stroke-width="4"/>`).join('')
|
||||
+ `<path d="M70 140 q10 30 -6 44 M100 140 q-4 26 10 40 M130 140 q8 22 -2 38" fill="none" stroke="${C.soil}" stroke-width="4"/>`,
|
||||
'fallen-petals': [[60, 110, -20], [110, 90, 25], [140, 130, 60]].map(([x, y, r]) => `<ellipse cx="${x}" cy="${y}" rx="34" ry="22" fill="${C.rose}" stroke="${C.ink}" stroke-width="4" transform="rotate(${r} ${x} ${y})"/>`).join(''),
|
||||
'petal-folded': `<circle cx="100" cy="100" r="86" fill="${C.lamp}" opacity=".35"/><path d="M100 30 C 170 60, 160 160, 100 170 C 40 160, 30 60, 100 30z" fill="${C.rose}" stroke="${C.ink}" stroke-width="5"/>
|
||||
<path d="M100 30 C 120 90, 120 130, 100 170" fill="none" stroke="${C.petal}" stroke-width="6"/>`,
|
||||
'petal-open': `<path d="M100 20 C 190 50, 190 160, 100 182 C 10 160, 10 50, 100 20z" fill="${C.petal}" stroke="${C.ink}" stroke-width="5"/>`,
|
||||
'garden-chair': `<rect x="60" y="40" width="80" height="70" rx="8" fill="${C.wood}" stroke="${C.ink}" stroke-width="5"/>
|
||||
<path d="M70 55 h60 M70 75 h60 M70 95 h60" stroke="${C.soil}" stroke-width="4"/>
|
||||
<path d="M50 110 h100 l-10 24 h-80z" fill="${C.petal}" stroke="${C.ink}" stroke-width="5"/>
|
||||
<path d="M62 134 v46 M138 134 v46 M80 134 v36 M120 134 v36" stroke="${C.wood}" stroke-width="9" stroke-linecap="round"/>`
|
||||
};
|
||||
|
||||
function garden(W: number, H: number, time: 'morning' | 'day' | 'sunset' | 'night'): string {
|
||||
const tint = {
|
||||
morning: { field: '#b8d1a0', far: '#c9dbe0', wall: '#b4a596', light: '#ffffff' },
|
||||
day: { field: C.meadow, far: '#b9cfa8', wall: '#a8957f', light: '#fff6d8' },
|
||||
sunset: { field: '#c9b07a', far: '#d9a98a', wall: '#a07b62', light: C.amber },
|
||||
night: { field: '#3c4a6a', far: '#46557a', wall: '#3a4466', light: C.lamp }
|
||||
}[time];
|
||||
const h = Math.round(H * 0.4);
|
||||
const bedY = Math.round(H * 0.72);
|
||||
return `<path d="M0 ${h} Q ${W * 0.3} ${h - 18} ${W * 0.55} ${h - 6} T ${W} ${h + 4} V ${H} H 0z" fill="${tint.far}"/>
|
||||
<path d="M0 ${h + 90} Q ${W * 0.5} ${h + 50} ${W} ${h + 110} V ${H} H 0z" fill="${tint.field}"/>
|
||||
<path d="M${W * 0.12} ${bedY - 70} Q ${W * 0.5} ${bedY - 150} ${W * 0.88} ${bedY - 70}" fill="none" stroke="${tint.wall}" stroke-width="44" stroke-linecap="round"/>
|
||||
<ellipse cx="${W / 2}" cy="${bedY}" rx="${W * 0.3}" ry="${H * 0.05}" fill="${C.soil}" stroke="${C.ink}" stroke-width="5"/>
|
||||
<circle cx="${time === 'sunset' ? 80 : W - 80}" cy="${h + 60}" r="26" fill="${tint.light}" opacity=".8"/>
|
||||
<path d="M0 ${h} H ${W}" stroke="${C.ink}" stroke-width="3" stroke-dasharray="14 10"/>`;
|
||||
}
|
||||
|
||||
function single(a: Asset): string {
|
||||
const { width: W, height: H } = a;
|
||||
switch (a.type) {
|
||||
case 'sheet': {
|
||||
const looks: RoseLook[] = [
|
||||
{ stage: 'full', eyes: 'half', mouth: 'smile' },
|
||||
{ stage: 'full', eyes: 'half', mouth: 'smile', tilt: -12 },
|
||||
{ stage: 'full', eyes: 'half', mouth: 'small', tilt: -20 },
|
||||
{ stage: 'full', eyes: 'half', mouth: 'small', back: true }
|
||||
];
|
||||
const figures = looks.map((l, i) => `<g transform="translate(${60 + i * 360} 40) scale(1.15)">${rose(l)}</g>`).join('');
|
||||
const heads: RoseLook[] = [
|
||||
{ stage: 'full', eyes: 'half', mouth: 'smile' },
|
||||
{ stage: 'half', eyes: 'closed', mouth: 'smile' },
|
||||
{ stage: 'full', eyes: 'closed', mouth: 'smile', blush: true }
|
||||
];
|
||||
// Close-ups: only the bloom, cropped by a nested viewBox.
|
||||
const close = heads.map((l, i) => `<svg x="${200 + i * 400}" y="660" width="320" height="320" viewBox="10 40 180 180">${rose(l)}</svg>`).join('');
|
||||
return `<rect width="${W}" height="${H}" fill="${C.paper}"/>${figures}${close}`;
|
||||
}
|
||||
case 'sprite':
|
||||
return fit(PROPS[a.id] ?? '', 200, 200, W, H, 0.7);
|
||||
case 'layer': {
|
||||
const time = (['morning', 'day', 'sunset', 'night'] as const).find((t) => a.id.endsWith(t)) ?? 'day';
|
||||
return garden(W, H, time);
|
||||
}
|
||||
case 'icon':
|
||||
return `<rect width="${W}" height="${H}" fill="${C.coral}"/><rect y="${H / 2}" width="${W}" height="${H / 2}" fill="${C.amber}" opacity=".6"/>
|
||||
<svg x="${W * 0.15}" y="${H * 0.12}" width="${W * 0.7}" height="${H * 0.76}" viewBox="0 30 200 230">${rose({ stage: 'full', eyes: 'half', mouth: 'smile', blush: true })}</svg>`;
|
||||
case 'spritesheet':
|
||||
return sheet(a);
|
||||
}
|
||||
}
|
||||
|
||||
/** One cell's drawing, sized to the cell it ships at. */
|
||||
function cellBody(id: string, W: number, H: number): string {
|
||||
const look = ROSES[id];
|
||||
if (look) return fit(rose(look), 200, 520, W, H);
|
||||
return fit(PROPS[id] ?? '', 200, 200, W, H, 0.7);
|
||||
}
|
||||
|
||||
function sheet(a: Asset): string {
|
||||
const g = a.grid ?? { cols: 1, rows: 1 };
|
||||
return cellBoxes(a.width, a.height, g.cols, g.rows)
|
||||
.map((b, i) => {
|
||||
const c = a.cells?.[i];
|
||||
if (!c) return '';
|
||||
const w = b.x1 - b.x0, h = b.y1 - b.y0;
|
||||
return `<svg x="${b.x0}" y="${b.y0}" width="${w}" height="${h}" viewBox="0 0 ${w} ${h}">${cellBody(c.id, w, h)}</svg>`;
|
||||
})
|
||||
.join('');
|
||||
}
|
||||
|
||||
const wrap = (id: string, W: number, H: number, body: string): string =>
|
||||
`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${W} ${H}" width="${W}" height="${H}">\n` +
|
||||
` <!-- Stand-in for ${id} (art/placeholders, CLAUDE.md §2): form and layout only, not art. Built by tools/art-prep. -->\n` +
|
||||
` ${body.replace(/\s*\n\s*/g, ' ')}\n</svg>\n`;
|
||||
|
||||
/** Every stand-in the board and the app may show: one per asset and one per sprite-sheet cell. */
|
||||
export function placeholders(m: Manifest): Map<string, string> {
|
||||
const out = new Map<string, string>();
|
||||
for (const a of m.assets) {
|
||||
out.set(a.id, wrap(a.id, a.width, a.height, single(a)));
|
||||
if (a.type === 'spritesheet') {
|
||||
const { width, height } = cellSize(a);
|
||||
for (const c of a.cells ?? []) out.set(c.id, wrap(c.id, width, height, cellBody(c.id, width, height)));
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
Reference in New Issue
Block a user