Pure Code Video Generation: A Technical Practice for Stunning Short Videos
This article explains how to generate a 30–60 second, 1920×1080, 30fps short video using only code, with no external images, video, audio assets, or generative model APIs. It covers turning subjective goals into measurable constraints, structuring prompts, designing a layered rendering pipeline, and implementing key techniques such as signed distance fields, curl-noise particles, gravitational lensing approximations, post-processing, and procedural audio. It also includes performance budgets, fallback strategies, and a reproducibility checklist for developers evaluating complex AI coding tasks.
1. Background: Why Pure Code Video Generation Is Worth Doing
A challenging technical task has recently drawn attention in developer communities: producing a 30–60 second, 1920×1080, 30fps short video using only code, without any external images, video, or audio assets and without calling generative model APIs. The video must have a clear visual concept, narrative pacing, and a reproducible engineering structure.
The value of this task is not about showing off. It tests three things at once: mathematics and graphics skills, software engineering ability, and aesthetic and narrative organization. For companies and developers, it is an intensive testbed for evaluating how well intelligent coding tools can plan, decompose, and deliver under long-context constraints.
2. Task Breakdown: Turning “Stunning” into Verifiable Engineering Metrics
“Stunning enough” is subjective and cannot be directly accepted or rejected. The professional approach is to translate it into quantifiable constraints:
- Technical constraints: zero external assets, zero generative API calls, and all visuals produced programmatically by code.
- Delivery constraints: complete source code, dependency notes, run commands, and render/export commands, with a final video file or complete frame sequence.
- Quality constraints: a narrative structure with a clear beginning, development, climax, and resolution; at least one high-complexity technique; and deliberate camera work, color, and composition.
- Engineering constraints: a performance budget and fallback plan so the project remains reproducible across different compute environments.
Only after converting subjective expectations into these four categories can the architecture design have a solid basis.
3. Prompt Design: Constraining Model Behavior with Structured Instructions
To make the model deliver consistently, the prompt needs a five-part structure: role, goal, hard constraints, delivery format, and scoring criteria. Example (illustrative):
Role: Creative technical director and graphics programmerGoal: Generate a 40-second 1080p/30fps short video using pure code; theme is openHard constraints:1) No external assets or generative APIs2) Visuals must be produced by mathematical functions/particles/shaders/procedural audio3) Must provide a reproducible project and export commandsDelivery:A Concept B Technical plan C Code structure D Run commands E Output naming F Self-assessmentScoring: code purity, reproducibility, visual impact, technical complexity, engineering quality, performance
The key is to put hard constraints first, fix the delivery format, and define scoring dimensions clearly. This significantly reduces cases where the model outputs pseudocode or only describes the expected effect.
4. Rendering Pipeline Design: Layered Decoupling Is the Basis of Reproducibility
A five-layer pipeline is recommended, with layers decoupled through files and configuration:
- Scene layer: defines the timeline, camera keyframes, and color script.
- Geometry layer: fractal distance fields, instanced particles, ring structures, and so on.
- Shading layer: procedural materials, lighting and shadows, and anti-flicker bloom.
- Post-processing layer: tone mapping, color grading, grain, and vignette.
- Output layer: frame sequence output, encoding and packaging, and audio mixing.
The benefit of layering is that any layer can be replaced or downgraded independently. For example, in a low-compute environment, high-precision geometry can be disabled while shading and post-processing are retained.
5. Key Technique 1: Hybrid Fractal Distance Fields and Ray Marching
A signed distance field (SDF) describes the distance to an object’s surface with a function, and ray marching approaches the surface step by step along a ray. A hybrid fractal can overlay multi-scale details in the same field, forming an organic “nucleus and veins” structure. Example code:
def sdScene(p, t):d = sdSphere(p - center(t), 0.6)d = min(d, fractalWarp(p, t, octaves=5))return ddef march(ro, rd, t):d, i = 0.0, 0while i < 128:h = sdScene(ro + rd * d, t)if h < 1e-4: return dd += h; i += 1return -1.0
Engineering note: the step limit and hit threshold determine the balance between performance and image quality. A fractal octave count of 4–6 is recommended; a higher count significantly increases rendering time.
6. Key Technique 2: Particle Curl Fields and Instanced Rendering
Tens of thousands of particles require instanced drawing and GPU buffers. A curl noise field keeps particle motion divergence-free and looks more fluid. Pseudocode:
for each particle i:v = curlNoise(pos_i, t) * gainpos_i += v * dtinstanceMatrix[i] = compose(pos_i, scale_i, rot_i)drawInstanced(mesh, count=N)
Performance budget suggestion: 8k–15k particles, with per-frame updates kept at the millisecond level. The fallback is to reduce the instance count or switch to point sprites.
7. Key Technique 3: Gravitational Lensing and Accretion Disk Approximation
Gravitational lensing can be approximated by offsetting the background sampling direction in the shading stage, while an accretion disk uses Doppler shift to modulate brightness and color temperature. Core idea:
dir = normalize(rayDir)dir += lensStrength * normalize(center - ro) / (dist^2 + eps)col = sampleBackground(dir)disk = dopplerDisk(p, t) # brightness and color temperature vary with velocity
This type of effect is “approximate physics.” It does not pursue scientific accuracy, but it must create a clear climax segment visually.
8. Key Technique 4: Post-Processing and Color Grading
Post-processing determines the cinematic feel. A common chain is: linear rendering → bloom extraction → multi-level blur accumulation → tone mapping (such as film/ACES-style curves) → stylized color grading → grain and vignette. Note that bloom needs anti-flicker handling, such as temporal jitter and threshold stabilization, to avoid brightness jumps between frames.
9. Procedural Audio and Audio-Visual Synchronization
Audio is also synthesized by code: build a beat grid with a fixed BPM, generate kick drums and pads by layering sine/sawtooth waves with envelopes, then apply simple reverb and limiting. The video timeline is aligned in bars so that the narrative structure matches the music sections. Example:
def synth(duration, bpm=96):beat = 60.0 / bpmt = np.linspace(0, duration, int(48000*duration))kick = np.sin(2*np.pi*55*t) * env(t, beat)pad = 0.3*np.sin(2*np.pi*220*t) + 0.2*np.sin(2*np.pi*277*t)return limiter(kick + pad)
10. Performance Budget and Fallback Plans
- Budget example: 1080p/30fps, 1200 frames, target under 200ms per frame; 5 fractal octaves, 12k particles, 3-level bloom.
- Fallback 1: reduce resolution to 720p or frame rate to 24fps.
- Fallback 2: disable high-precision geometry and keep shading and post-processing.
- Fallback 3: render the frame sequence in chunks and encode it together at the end to reduce peak GPU memory usage.
11. Reproducibility and Acceptance Checklist
- Fix random seeds and record dependency versions and run commands.
- Use a consistent naming rule for output frame sequences to support resumable rendering.
- Score acceptance across six dimensions: code purity, reproducibility, visual impact, technical complexity, engineering quality, and performance stability.
- Deliverables must include the concept description, technical plan, code structure, commands, output path, and self-assessment. None can be missing.
12. Conclusion
Pure code generation of stunning short videos is essentially about combining mathematics, graphics, audio synthesis, and software engineering into a reproducible pipeline. With the structured prompting, layered pipeline, key techniques, and fallback strategies described above, developers can reliably deliver high-quality work under different compute conditions. It also provides a reliable paradigm for evaluating the complex-task execution ability of intelligent coding tools.
