Code-Only Video Generation: Prompt Design and Evaluation Practices
Generating a short video entirely through code is a demanding benchmark for AI coding tools. This article explains how to define verifiable constraints, structure procedural graphics and audio, build a reproducible rendering pipeline, and evaluate visual quality alongside technical complexity and engineering discipline. It also outlines performance tiers and common delivery failures.
1. Why Code-Only Video Generation Makes a Useful Benchmark
Simple tasks such as writing a sorting function do little to distinguish the capabilities of modern AI coding tools. More revealing tests involve multi-stage workflows, strict constraints, and verifiable results. These tasks assess mathematical and graphics knowledge, project organization, and the ability to maintain consistency through repeated revisions.
Generating a 30–60-second video at 1920×1080 and 30 fps entirely through code meets these criteria:
- No external assets: Every pixel must be generated algorithmically rather than assembled from existing media.
- A required video export or complete frame sequence: Third parties can verify the result independently, rather than relying on a visual mockup.
- A coherent narrative arc: The model must coordinate camera movement, color, and composition over time.
- A performance budget and fallback strategy: The implementation must account for hardware differences and demonstrate engineering judgment.
In effect, this task turns aesthetics into an engineering deliverable that can be compiled, rendered, and scored.
2. Prompt Design: Turn Visual Ambition into Verifiable Requirements
Subjective judgment alone is difficult to scale. The first priority is therefore to organize constraints into layers: hard constraints, creative requirements, delivery format, and scoring criteria.
Hard constraints are non-negotiable. Creative requirements define the quality target. The delivery format standardizes the submission, while scoring criteria make evaluation priorities explicit.
The following prompt template can be reused:
Role: Creative technical director and graphics programmer.Goal: Generate a 30–60-second video at 1920×1080 and 30 fpsentirely through code.Hard constraints:1. Do not use external images, video, or audio assets.Do not call generative media APIs.2. Generate visuals and sound using mathematical functions,fractals, particle systems, shaders, procedural textures,and procedural audio synthesis.3. Provide a reproducible project: source code, dependencies,execution commands, and rendering/export commands.4. Actually export a video or a complete frame sequence,and explain how to assemble it into MP4/GIF.5. Do not provide pseudocode or visual mockups.If response length is limited, prioritize runnable core visuals.Creative requirements:Define a clear visual concept.Implement at least one technically complex technique.Design camera movement, color, and composition deliberately.Provide a performance budget and fallback strategy.Delivery format:A. ConceptB. Technical approach and challengesC. Code and file structureD. Execution and rendering commandsE. Output paths and frame-naming conventionF. Self-assessment
Constraint 5 and section F are particularly important. Explicitly prohibiting pseudocode helps reduce submissions that look plausible but cannot run. Requiring self-assessment encourages the model to check whether its deliverables are internally consistent before finishing. In practical evaluations, this step can reduce cases where a model claims to have exported a video but provides no export command.
3. A General Technical Stack for Procedural Visuals
High-quality solutions to this task commonly combine six closely connected modules.
3.1 Procedural Geometry: Signed Distance Fields and Ray Marching
Signed distance fields (SDFs), combined with ray marching, provide an economical way to render static and animated geometry entirely through code. Fractal forms, such as Mandelbulb-style iterations, offer richly detailed surfaces. Blending them with analytic spheres can produce organic shapes:
float map(vec3 p) {float dAnalytic = sdSphere(p - center, radius);float dFractal = sdMandelbulb(p, power); // Iterative fractalfloat d = mix(dAnalytic, dFractal, 0.65); // Shape blendingreturn d * 0.5; // Safety factor to reduce overshoot}
The step-size safety factor affects the balance between rendering artifacts and performance. Distance-field evaluation is a major computational expense and should be central to the rendering budget.
3.2 Relativistic Visuals: Gravitational Lensing and Doppler Effects
For a spectacle inspired by physics, ray marching can accumulate approximate gravitational deflection along each ray’s path around a central body. This creates ring-like distortions in the background star field.
An accretion disk can use a temperature-to-frequency mapping, with its inner regions appearing more blue-white. Adding Doppler beaming makes one side of the rotating disk brighter than the other.
These effects do not require a full numerical relativity simulation. A visual approximation can be sufficient if it preserves the appropriate qualitative features.
3.3 Particle Systems: Curl-Based Noise Fields
Simply assigning random velocities to tens of thousands of instanced particles can produce an uneven distribution. A divergence-free velocity field helps create turbulent motion while preserving a more uniform distribution.
One construction uses the cross product of the gradients of two independent scalar potential fields:
curl(p) = cross(∇N1(p), ∇N2(p)) // Cross product of two independent potential gradientsv = curl(p * frequency + time * drift)
Combined with instanced rendering and additive blending, this approach can create galaxy-scale dust bands.
3.4 Post-Processing
A useful processing order is:
- Bloom with flicker suppression: Multiscale downsampling, a highlight threshold, and temporal jitter suppression.
- Tone mapping: A filmic curve that compresses HDR values into the display range.
- Color grading: A consistent palette across the sequence.
- Fine-grained dithering: Reduced banding in 8-bit output.
Applying bloom before tone mapping is important for retaining a luminous appearance.
3.5 Procedural Audio and Audiovisual Synchronization
Audio must also be synthesized in code. Low-frequency sine sweeps can create rumbling sounds, while filtered noise can suggest a stellar wind. Envelopes and reverberation can be combined at a 48 kHz sample rate.
A reliable synchronization strategy is to use audio envelopes to drive visual parameters, such as bloom intensity or camera-shake amplitude. This is more consistent than allowing separate audio and visual timelines to evolve independently.
3.6 Timeline and Narrative
Divide the 30–60-second sequence into four stages:
- Quiet establishment: A wide shot with low saturation.
- Structural reveal: A camera push-in as fractal detail unfolds.
- Climax: An accretion disk, a particle vortex, and peak color saturation.
- Resolution: A pullback with gradually fading brightness.
Drive all parameters through a shared keyframe interpolation function to prevent inconsistent time bases across modules.
4. Reproducible Rendering and Delivery
Reproducibility is a core scoring criterion, not an optional addition. A suitable project structure is:
project/├── src/ # Shaders, scene code, and particle code├── audio/ # Audio synthesis scripts├── frames/ # Rendered frame sequence└── out/ # Final video
The following commands illustrate the rendering and encoding workflow. The renderer, audio synthesizer, and encoder placeholders must correspond to the actual project and environment.
# 1. Render the frame sequence using a consistent naming convention# frames/f_00000.png ... f_01799.png (30 fps × 60 seconds)render --width 1920 --height 1080 --fps 30 --out frames/f_%05d.png# 2. Synthesize audiosynth-audio --rate 48000 --duration 60 --out out/score.wav# 3. Encode MP4 using a general-purpose encoder# The exact command depends on the environment<encoder> -framerate 30 -i frames/f_%05d.png -i out/score.wav \-c:v <h264> -crf 18 -pix_fmt yuv420p -c:a aac out/final.mp4
Fixed-width, zero-padded frame numbers ensure that lexicographic order matches chronological order. Overlooking this detail can lead to incorrectly ordered frames during cross-platform assembly.
5. Performance Budgets and Fallback Strategies
Declare the performance budget explicitly and provide selectable quality tiers:
| Tier | Resolution / Frame Rate | Particle Count | Ray-Marching Steps | Target Environment |
|---|---|---|---|---|
| High | 1920×1080 / 30 fps | 12,000 | 96 | Workstation with a discrete GPU |
| Medium | 1280×720 / 30 fps | 6,000 | 64 | Laptop with integrated graphics |
| Low | 960×540 / 24 fps | 2,000 | 40 | CPU-only fallback without hardware acceleration |
These tiers describe intended configurations rather than guaranteed performance.
Reduce quality in this order:
- Lower the particle count and ray-marching step count.
- Lower the resolution.
- Lower the frame rate only as a last resort, coordinating timing and duration so audiovisual synchronization remains intact.
The lower tiers are fallback options; they do not meet the original 1920×1080, 30 fps delivery requirement.
6. Scoring Criteria and Common Failure Modes
| Dimension | Weight | Evaluation Criteria |
|---|---|---|
| Code-only compliance | 25% | No external assets or generative media API calls |
| Reproducibility | 25% | Executable commands, consistent frame naming, and a complete encoding pipeline |
| Visual impact | 20% | Clear concept and deliberate composition and color |
| Technical complexity | 15% | At least one complex technique implemented correctly |
| Engineering and performance | 15% | Clear structure, explicit budgets, and selectable fallback settings |
Four failures recur frequently:
- Providing only pseudocode or visual mockups.
- Claiming that a video has been exported without supplying export commands.
- Listing advanced technical terms while leaving the implementation empty.
- Using inconsistent time bases across modules, causing audiovisual misalignment.
Checking these issues first can filter out many low-quality submissions in roughly a minute.
7. A Framework That Transfers Beyond Video
The value of this task extends beyond testing whether a model can generate an impressive video. It provides a reusable evaluation method:
- Use hard constraints to remove ambiguity.
- Use a fixed delivery format to require a complete workflow.
- Use executable verification instead of relying solely on subjective claims.
- Use performance budgets and fallback strategies to assess engineering maturity.
With modest adjustments, the same framework can support procedural chart animations, product demonstration videos, and short data-visualization sequences. It can also serve as a standardized benchmark for AI coding tools on complex, multi-stage tasks.
