Code Generation for Visual Content: The Shift from Pixel Synthesis to Code Synthesis

    This article examines a shift in AI-driven visual generation, where large language models write code that browsers render in real time instead of diffusion models producing pixels directly. It breaks down the layered architecture behind these outputs, the role of camera models and scene graphs in adding depth, easing and keyframes as transitions, code-based audio, prompt constraints that keep generated code runnable, and the engineering requirements for performance, fallback, and maintainability. It also outlines where code synthesis falls short compared with dedicated video generation.

    Overseas AI communities were recently flooded with a batch of unusual works: a slide deck with more than seven million views, a hand-drawn-style short film, and a polished 3D mini-scene. None of them were rendered pixel by pixel by a video generation model. Instead, a large language model wrote the code, and the browser rendered it live. The pattern points to a broader change: visual generation is moving from pixel synthesis to code synthesis. This article takes a neutral look at the underlying principles, implementation paths, and engineering constraints.

    From Pixel Generation to Code Generation

    For the past two years, the mainstream approach to visual generation has been the diffusion model: you supply a prompt, and the model outputs an image or a sequence of video frames. The strength of this route is visual quality. The weaknesses are limited controllability, high editing cost, and a large compute cost per generation.

    The works that triggered the recent discussion take a different route. The model outputs structured code: HTML, CSS, JavaScript, and scene descriptions for 3D rendering. A runtime interprets and executes that code to produce the visuals, while an audio context synthesizes the music in real time. Put differently, the model does not paint the frame; it writes the program that generates it.

    The shift yields three immediate benefits:

    • Editability: changing a single parameter adjusts the global style, with no need to regenerate.
    • Small size: a deck containing thirteen scenes is only about five megabytes, because it stores logic rather than pixels.
    • Interactivity: camera moves, transitions, and data charts can all respond to user input.

    Anatomy of a Moving Slide Deck

    Layered Architecture

    A typical implementation has four layers: a content layer (structured data and copy), a presentation layer (layout and styling), a motion layer (timelines and easing functions), and an interaction layer (events and state management). The model’s job is to generate code that is internally consistent across all four layers, not scattered fragments.

    Adding Depth: Camera and Scene Graph

    What gives a flat chart a sense of space is the introduction of a camera model and a scene graph. Elements are placed in a 3D coordinate system, and moving the camera’s position and orientation produces the effect of camera work. Illustrative code:

    1. // Pseudocode: camera movement instead of conventional page turns
    2. camera.position.lerp(targetPos, 0.08);
    3. camera.lookAt(sceneCenter);
    4. // Layer chart elements along the z axis to create depth
    5. chart.layers.forEach((layer, i) => layer.position.z = i * 0.6);

    Transitions Are Timelines

    Cinematic transitions are not special effects; they are combinations of easing functions and keyframes. A common approach splits a transition into four stages: fade out, displacement, scale, and fade in, each using a different easing curve to avoid the mechanical feel of linear motion.

    Audio as Code

    Background music can be generated by layering oscillators with envelopes, or it can reference licensed audio assets. The former adds zero bytes but offers a limited timbre; the latter sounds better but requires handling copyright and loading strategy.

    Prompt Design: Getting Reliable, Runnable Code

    Code generation tasks fail in highly concentrated ways: unclosed tags, undefined variables, incorrect resource paths, and performance collapse. A reusable constraint template looks like this:

    1. Role: Senior front-end engineer
    2. Goal: Generate a runnable single-file 3D slide deck
    3. Constraints:
    4. 1. Use only native web technologies; do not load external resources.
    5. 2. Declare all scene data as constant arrays; no scattered magic numbers.
    6. 3. Every scene must define both an enter and an exit state.
    7. 4. Keep the total number of rendered objects under 200; enable a fallback strategy beyond that.
    8. 5. Output the complete file; do not use ellipses.

    The key is to translate “aesthetic requirements” into “verifiable engineering constraints.” Models respond inconsistently to vague adjectives, but they follow counts, structures, and naming conventions far more reliably.

    Engineering in Practice: Performance, Compatibility, Maintainability

    • Performance budget: set upper limits for frame rate, draw calls, and memory usage, and automatically reduce the effects level when a limit is exceeded.
    • Fallback chain: degrade from 3D to 2D, then to static layout, so the output opens on any device.
    • Asset strategy: serve large assets from object storage, paired with a content delivery network to reduce time to first render.
    • Observability: connect logging and monitoring with alerting, collect render times and error rates, and close the iteration loop.
    • Team collaboration: keep prompt templates, validation scripts, and the rendering foundation in a code repository so the output is not a one-off artifact.

    Teams that rely on Baidu AI Cloud’s underlying capabilities can host rendered output in object storage, run build and validation jobs on a container platform, and track live performance through the monitoring and alerting system, forming a complete path from generation to release.

    Capability Boundaries and a Realistic View

    Code synthesis is not a universal solution. It excels at structured, interactive, size-sensitive content such as slide decks, data visualization, and teaching animations. It still falls short of dedicated video generation for real human performance, complex lighting, and long continuous shots. In addition, the “capability jumps” observed during a model’s grayscale testing often come from changes to prompt strategy and inference configuration, and should not be attributed simply to parameter scale.

    The practical recommendation for developers is to establish a standard workflow of prompt template, automated validation, performance budget, and fallback release, turning an uncontrollable generation step into measurable engineering steps. Once the cost of generating visual content drops by an order of magnitude, the real competitive edge returns to content structure and narrative design.