Prompting for Code-Generated Images and Videos: A Reproducible Contract
Code-generated visuals require a different kind of prompt from generative model images. This article presents a four-part prompt structure for specifying drawing tools, verifiable visual elements, reproducibility constraints, and delivery acceptance so that images and loop videos can be rerendered, reviewed, and revised consistently.
Giving the visual output to code is not the same as asking a generative model to “imagine” the scene. The two approaches impose different constraints. Model prompts seek semantic association; code prompts require computability, reproducibility, and acceptance criteria. If you omit the tool boundary, the execution side may switch to ad hoc collage, external assets, or a process that cannot be replayed. If you omit time and delivery standards, even a 30-second loop can fail to match at the seam. The following prompt skeleton explains what each layer should contain, why it matters, and what can go wrong when the wording is too loose.
1. Define the Production Method Before Writing the Visual
The prompt should begin by specifying the drawing interface, resolution, frame rate, duration, and whether external images, font files, or irreproducible random sources are allowed. Write these as hard constraints, not preferences.
A recommended opening should include four things:
- Carrier: a browser 2D canvas or a similar immediate-mode drawing API, with no reliance on cross-frame residual state.
- Specifications: for example, width 1920, height 1080, 30 frames per second, total duration 30 seconds.
- Pure function: each frame is determined only by time
t, and the implementation exposes a seekableseek(t). - Reproduction: random numbers use a fixed seed; every periodic motion has a period that divides the total duration evenly, so the last frame matches the first.
The reason is concrete. If “any method of producing the image” is allowed, the implementation may switch between vector drawing, pixel filtering, and external asset compositing, making style and performance uncontrollable. If the animation depends on the previous frame’s particle positions or an accumulator, then jumping to a point, rerendering a single second, or capturing frames in parallel will produce different results. The most common loop-video failure is that the phase at second 30 does not return to second 0: star positions jump, the light band is out of phase, or the reflection and the source object are not synchronized. Writing “time as a pure function plus periods that divide the duration” into the prompt is effectively defining the acceptance standard in advance.
A schematic structure can be constrained like this, without binding the prompt to a specific runtime environment:
Visuals are drawn pixel by pixel on a 2D canvas.frame(t) reads only t, canvas dimensions, and a fixed seed.Do not read pixels from the previous frame. Do not use wall-clock time.Every period T of sine and noise sampling must divide 30 seconds evenly.seek(t) must produce the same result as playing from the beginning to t.
2. Write the Visual as Verifiable Elements, Not a Pile of Adjectives
The visual section should be layered: space, light source, motion, unique accent color, prohibited items, and reference boundaries. Each layer should be checkable by a person or a program.
For a night-loop example, an effective description usually includes:
- Space: a deep-night fjord, snow-covered mountains on both shores as silhouettes, water close to a mirror and fully reflecting the sky.
- Main light: aurora rising from the horizon as vertical bands with longitudinal fibers, mainly green with a small amount of pale purple at the edges, swaying slowly overall.
- Static points: stars stay fixed and do not twinkle, avoiding “breathing-light” brightness noise that would break the long-exposure feel.
- Unique warm color: one small cabin at a corner of the shore, with warm yellow light in the window. No second warm color appears in the entire piece, establishing a cold-warm contrast.
- Texture boundary: borrow only the grain, motion blur, and warm-cool relationships of long-exposure nature photography; no text, watermarks, recognizable landmarks, or reproduction of any specific photograph.
- Density: require the amount of visual information expected from a natural-documentary night scene, including fibers, snow layers, and synchronized reflections, rather than uniform gradient blocks.
“Beautiful,” “cinematic,” and “premium” can hardly guide code. Code needs to know whether the reflection follows the same phase as the light band, whether star brightness modulation is allowed, and whether the snow is a single silhouette or three value layers for foreground, midground, and background. Write these as observable phenomena so that later review can distinguish which effects are simulated by geometry or noise and which merely look similar.
The same layering applies to still-image prompts. Consider an afternoon interior with a beam of light: white walls, wood floor, a divided glass door, light entering from a single direction, dust visible only inside the light cone, and soft falloff on the wall rather than uniform color. Resolution, composition negative space, and whether text is allowed should be fixed just as they are for motion. Still images are easily written as “a mood image,” and the result can contradict itself in door/window proportions, floor perspective, and light-cone direction. Specify the perspective vanishing point, light-source azimuth, and unique warm color or highlight to significantly reduce rework.
3. Technical Constraints Should Serve Reproducibility, Not Showmanship
The technical section is not a list of fashionable terms. It is there to close off uncontrolled degrees of freedom. At minimum, specify five constraints.
First, normalize time. Use t in [0, duration), and use (t mod T) / T for internal phase. Do not use frame indices with implicit accumulation; otherwise, motion speed changes after dropped or duplicated frames.
Second, seed the noise. If clouds, fibers, or snow highlights use noise fields, fix the seed, frequency, and number of octaves. Multiple renders at the same t must produce the same pixel trend. Antialiasing or supersampling may be allowed, but a new seed must not be drawn on every run.
Third, close the loop. The periods of light-band sway, water ripples, and dust drift should be integer factors of the total duration, such as 10 seconds, 15 seconds, or 30 seconds. If the period is 7 seconds and the clip is 30 seconds, the first and last frames will necessarily jump.
Fourth, couple the motion. The reflection is not a flipped image pasted in. State that it uses the same time parameter as the source object, with acceptable attenuation and slight vertical stretching. The star field and mountain silhouettes should be static by default; only the aurora and its reflection move, avoiding a whole-frame “breathing” effect.
Fifth, define the rendering path. Draw each frame offscreen, then composite the frames into video in frame order. Because there is no cross-frame state, parallel frame capture can be shuffled and later stitched by timestamp. Write this into the prompt; otherwise, the implementation may quietly use recursive filters or a video-editing timeline, which is both hard to reproduce and hard to explain when a frame fails.
The cost of these constraints is narrower expressiveness: you cannot rely on real fluid simulation or cross-frame particle lifetimes for complex trails. What you gain is consistency across the sample, the full piece, and a rerun. For technical demos that need archiving, review, and revision, consistency is usually more important than one accidentally beautiful result.
4. Delivery Standards Determine When to Stop
The final layer of the prompt is acceptance, not another sentence asking for “make it look good.” A practical structure has three delivery stages.
- First deliver a sample of about 5 seconds or an equivalent still-image sequence to confirm composition, cold-warm ratio, fiber density, and the first/last phase strategy.
- After confirmation, render the full duration and ensure that total frames, frame rate, and resolution use the same parameter set as the sample.
- Attach a one-page note: which phenomena are simulated by geometry, gradients, noise, or periodic functions; which are not implemented, such as real atmospheric scattering, water-surface Fresnel effects, or physical energy conservation for lens flare.
The value of the note is often underestimated. In a code-generated night scene, “aurora fibers” are most likely vertically modulated noise bands, not ionospheric structure; “long exposure” is most likely low contrast, slight blur, and static stars, not true integrated exposure. Writing down the simulation boundary prevents reviewers from rejecting a declared stylistic procedural image with the physical standards of photography, and prevents unimplemented effects from being mistaken for completed ones.
Also state the negative items: no text, no watermark, no recognizable place names or building landmarks, and no copying the composition fingerprint of a specific work. Style references should learn only the texture type, not the object layout of a particular photograph. This avoids copyright and identifier disputes, and it also prevents the model or drawing code from trying to “match the answer.”
5. A Reusable Prompt Order
In practice, fixing the prompt into four sections is more stable than continually appending adjectives.
- Tool and specifications: drawing API, resolution, frame rate, duration, whether pure code is required, and whether external assets are prohibited.
- Visual contract: subject, spatial layers, light source and unique accent color, moving objects and static objects, texture reference and its boundaries.
- Technical contract:
seek(t), fixed seed, periods that divide the duration, reflection or shadow synchronized with the subject, per-frame output followed by compositing. - Delivery contract: short sample first, full piece second, attached list of simulated and unimplemented effects, plus prohibited items.
For still images, you can remove frame rate and looping, but keep resolution, pure drawing, seed, and the note on “what is simulated.” For multi-shot pieces, give each shot its own timeline and loop or cut rules; do not pack multiple mutually exclusive styles into one description.
After writing the prompt, check it with three questions: Will the same moment look identical after another run? Will jumping to an arbitrary second and continuing match sequential playback? Can the viewer see a seam when the last frame returns to the first? If all three answers are yes, the prompt can drive pure-code imaging rather than a lucky description.
Common rework can also be located against these four sections. If the image looks washed out and the layers blur together, the visual section probably described atmosphere but did not specify value layering. If the light band and reflection move independently, the technical section did not specify coupling. If the full piece can only play from the beginning and cannot rerender two seconds in the middle, state was left between frames. If the full piece and the sample have different compositions, the delivery section did not lock the seed, resolution, and phase formula. Assigning the failure to a specific section is more effective than repeatedly adding “more realistic.”
If the image needs a warm anchor, keep the number to one where possible. One warm window in a night scene or one main light in an afternoon interior gives the code a contrast anchor. Too many anchors average out the cold-warm relationship and the hierarchy, and every element ends up with “a little light,” leaving the image without a visual center. Negative items should also be few and hard: no text, no watermark, no second warm color, no twinkling stars is more constraining for drawing branches than a long list of style adjectives.
Finally, state the boundary clearly. This kind of prompt is suitable for procedural graphics, data visualization, and stylized loop backgrounds. It is not suitable for claiming that physically correct atmosphere, water, or camera simulation has been completed. Proactively writing down what is not implemented is part of professional delivery, not a weakness. When the tool, visual, time, and acceptance layers are all closed, code-generated images and videos move from “might look acceptable” to “repeatably producible.”
