collage-code-motion 是做什么的?
Turn a brand / product / theme into a 10–20 second collage-style quick-cut motion piece. The entire film is an HTML Canvas program:
each shot is a draw(g, l, f) function, Playwright captures each frame, ffmpeg composites, and audio.py generates a beat-synced audio track from the timeline.
The user acts as the art director, and you handle everything from storyboarding to the final render, modifying individual shots based on feedback.
Two layouts (CONFIG.layout):
showcase— 1920×1080: a live "code panel" on the left that types itself out, highlights the current line, and connects to the visuals; the final film (1000×1000) is on the right. Ideal for "making videos with code"-style content.film— 1080×1080 pure film, suitable for direct distribution.
Directory
engine/ core.js (canvas / easing / textures / collage tools / procedural sneakers and eyes) · presets.js (12 ready-made shots) · engine.js (compositing, transitions, code panel, render entry point)
scripts/ build.py · render.js · audio.py · prep_assets.py · preview.sh · make_video.sh · contact_sheet.sh
template/ Minimal starter project (6 shots, demonstrates text overlays and swapping the main subject)
examples/jump-vol01/ Full example: 27 shots, 15 seconds, 120 BPM, includes CC0 photo assets
references/ api.md (all functions and preset parameters) · shot-grammar.md (rhythm and visual rules) · assets.md (sources, processing, licensing)
A project = one folder: config.js + timeline.js + assets/. Engine files don't need to be modified.
Requirements
Requires Node 18+, playwright (with Chromium), Python 3 + numpy pillow, ffmpeg.
In the skill directory run npm install && npx playwright install chromium (if Chromium is already installed, set CHROMIUM_PATH).
Fonts: display fonts default to Inter Display / Inter / Archivo Black, Chinese to Noto Sans CJK / PingFang, monospace to JetBrains Mono / DejaVu Sans Mono, emoji to Noto Color Emoji / Apple Color Emoji. Use fc-list (Linux) to confirm; if fonts are missing, replace them in CONFIG.fonts with fonts available on the system, otherwise Chinese and emoji will appear as boxes.
Workflow
- Set direction (ask once): theme / brand name, duration (default 15 seconds), layout (showcase or film), language, primary color, whether they have their own assets (product photos, AI-generated images). If the user doesn't specify, use defaults and explain your choices in the response.
- Create the project: Copy
template/to a working directory (e.g.,projects/<brand>/), modifyconfig.jswith the brand, project, file, badge, palette, assets. - Prepare assets: The richness of the collage comes from real images. Follow
references/assets.md:- User-provided or AI-generated images →
python3 scripts/prep_assets.py img.jpg --out <proj>/assets --name hero --treat color duotone:#2a0a12:#FF8FB1 halftone bw circle cutout - When no images are available, use CC0 / public domain images (scikit-image sample images, NASA photos), plus emoji stickers and procedural graphics. Do not use web images with unclear sources or licenses, nor recognizable real people's photos for advertising.
- Add every processed file to
CONFIG.assets, and reference them in code usingIMG['<filename without extension>'].
- User-provided or AI-generated images →
- Write the storyboard → timeline.js: First list the shot table (name, frames, one-line description) according to
references/shot-grammar.md, then write the code. Reuse presets withpreset(name, k, {text overlay}); for new shots, use core utility functions to draw (seeexamples/jump-vol01/timeline.js). Each shot gets 1–3lines, which are the "code" displayed on the code panel. - Preview with keyframes:
bash scripts/preview.sh <proj> "6,20,44,...", then use the Read tool to check the generated sheet image. Focus on: text being cropped or overlapping, main subject leaving the frame, timecode covering text, blurry images, clashing colors. Fix and re-preview. - Render:
bash scripts/make_video.sh <proj> <proj>/out.mp4. 15 seconds, 1080p takes about 1–2 minutes. After rendering, check the auto-generated_sheet.jpgto verify the rhythm of the whole film. - Deliver and iterate: Send the MP4 to the user (if they need the source code, zip the project folder together with it). If the user says "Shot N is too slow / change color / change text", modify the corresponding shot's
dur,k, colors or options, then re-render.
Key Rules (from real feedback)
- Pace is faster than you think: 120 BPM, shot duration is 6 / 12 / 18 frames (24 fps). No shot exceeds 18 frames except the ending. Every 2–4 frames within each shot must introduce a new element. A version with 30-frame shots was reported as "too slow" by the user.
- Assets must be dense: Most shots need at least one layer of a photo or texture (photo card, halftone, duotone, brick wall, starfield), topped with stickers, tape, and big text. A version using only pure vector graphics was reported as "assets are not rich enough".
- Cycle background colors (red, yellow, green, cyan, off-white, black starfield); no two adjacent shots should share the same background color.
- Tear transitions (
trans:'tear') can appear at most 4 times in the entire film; other transitions usepunch:true(push-in) plus a white flash at the cut (added automatically by the engine). - Before the ending, include a
replayflashback (switching every 2 frames to previous shots); the ending lockup stays for about 1.5 seconds. - Keep the main subject and text away from the bottom-left (timecode) and top-right (brand badge) areas.
- In
showcaselayout, the code panel'slinesmust look like real code (film.at(@).method(args));@is replaced with the absolute frame number. Asset lines display thumbnails and license attributions; labels must be truthful: photos state CC0, user-provided, or AI-generated.
Common Issues
- Render error
Tainted canvas→ The page must be opened via the built-in HTTP server from render.js, not with file://. - Chinese or emoji appear as boxes → Missing fonts, see the "Requirements" section.
- Black screen or missing images → Check render.js output for
MISSING ASSET, verify filenames inCONFIG.assets. - Wrong duration → Total frames equal the sum of all
durvalues (theframesintimeline.json).