How LLMs Generate Visual Content with Code: A Technical Breakdown
This article explains how large language models generate visual content by writing code rather than outputting pixels directly. It covers code as an intermediate visual representation, the four observable dimensions of aesthetics, a six-stage production pipeline, prompt and context design, a three-layer evaluation system, cloud deployment considerations, and key risks and boundaries. Developers will find a practical methodology for turning occasional impressive output into a repeatable, verifiable workflow.
Recently, a wave of unusual creations has been making the rounds in overseas AI communities: a presentation with animations that has racked up more than seven million views and nearly thirty thousand likes, a sixty-second hand-drawn style animation, and a detailed 3D interactive mini-game. Notably, these works were not produced directly by dedicated video generation models. Instead, large language models “computed” them frame by frame by writing code. On November 25, a tech outlet reported that a leading model vendor appears to be running a canary test of a new model. Some users noticed a clear shift in output style when using the same high-tier model, and the community has tentatively called it the next-generation version, with visual aesthetics that exceeded expectations.
This article does not focus on any specific product. Instead, it abstracts the phenomenon into a general engineering question: how do large language models generate visual content using code as an intermediate medium? The discussion is organized into five layers: principles, pipeline, prompts, evaluation, and cloud deployment, forming a practical methodology.
1. The Technical Essence Behind the Phenomenon: Code as a Visual Intermediate Representation
Traditional visual generation relies on diffusion models or rendering-specific networks that output pixels or frame sequences directly. Large language models take a different path: they translate a “scene” into an executable structured description. The chain can be summarized as:
natural language intent → structured scene description → runnable code → renderer execution → pixel output
This approach has three advantages.
First, it is explainable and editable. The scene is determined by parameters, so changing a coordinate or an easing function allows local adjustments without regenerating the whole piece.
Second, it is deterministic and reproducible. The same code produces the same result in the same rendering environment, which makes version management and regression testing straightforward.
Third, it requires no extra model dependency. As long as the target environment supports graphics rendering, the model can create content without calling any image or video generation service.
A minimal illustrative chain follows (using a generic 2D canvas interface, not pointing to any specific library):
// Scene description: a circle slides in from the left and fades outconst scene = {duration: 3000,layers: [{type: 'circle',from: { x: 0, y: 200, opacity: 0 },to: { x: 400, y: 200, opacity: 1 },easing: 'easeOutCubic'}]};function renderFrame(t, ctx) {const p = Math.min(t / scene.duration, 1);const e = easeOutCubic(p);const l = scene.layers[0];ctx.globalAlpha = l.from.opacity + (l.to.opacity - l.from.opacity) * e;ctx.beginPath();ctx.arc(l.from.x + (l.to.x - l.from.x) * e, l.from.y, 40, 0, Math.PI * 2);ctx.fill();}
2. Why Aesthetics Have Become the Key Differentiator of New Models
When generating visuals with code, the hard part has never been whether it runs, but whether it looks good. Aesthetics can be broken down into four observable dimensions:
- Composition and whitespace: whether element density, visual focus, and hierarchy are well balanced;
- Color and contrast: whether primary and secondary colors work together, whether contrast meets readability requirements, and whether there is a consistent color language;
- Motion rhythm: whether the choice of easing curves, duration allocation, and staggered delays create rhythm rather than mechanical uniform speed;
- Detail consistency: whether corner radii, shadows, font weights, and spacing are unified, forming a design system rather than a pile of elements.
When the community describes the new model version as having aesthetics beyond expectations, the underlying reason is that the joint distribution across these dimensions is more concentrated, with fewer “runs but looks bad” samples. The takeaway for developers is that visual generation quality should be evaluated with a scoreable checklist built from these four dimensions, rather than a single subjective judgment.
3. Engineering Pipeline: From a One-Line Requirement to a Deliverable
A robust production pipeline usually contains six stages:
- Intent parsing: breaking down a request such as “make a product introduction presentation, tech style, blue as the primary color” into structured constraints;
- Design specification generation: producing tokens for color, font size, spacing, and corner radius first, then generating content;
- Code synthesis: producing a runnable, componentized project rather than a single-file pile;
- Rendering and recording: rendering frame by frame in a headless environment, then compositing into video or exporting as an interactive page as needed;
- Automated validation: type checking, build, and visual regression screenshot comparison;
- Human final review: handling only brand and narrative issues that are hard for the model to judge.
“Specification first, content second” is the key engineering habit. Example tokens:
{"color": { "primary": "#2B6CF6", "bg": "#0B1020", "text": "#E6EAF2" },"space": { "unit": 8 },"radius": { "sm": 6, "lg": 16 },"font": { "title": 48, "body": 20 }}
4. Prompt and Context Design: The Lever That Sets the Ceiling
With the same model, differences in prompt quality can produce several-fold differences in results. A four-part structure is recommended: role + constraints + structure + acceptance.
- Role: a senior frontend and motion engineer;
- Constraints: use only standard graphics interfaces, no external assets, finish within sixty seconds, frame rate of thirty;
- Structure: output design tokens first, then components, and finally the timeline;
- Acceptance: provide a self-check list, such as contrast, no overlapping elements, and loopable animation.
For long tasks, it is advisable to make the storyboard explicit, letting the model generate and self-check shot by shot, avoiding a quality collapse caused by generating overly long code in one pass.
5. Quality Evaluation: Building a Quantifiable Acceptance System
A three-layer evaluation is recommended: the static layer (build and type-check pass rate), the structural layer (component reuse rate and token coverage), and the visual layer (structural similarity of keyframe screenshots, contrast detection, and distribution of animation durations). Turning “looks good” into regression-friendly metrics is what enables continuous iteration.
6. Cloud Practice: Turning Creative Production into a Scalable Service
When this capability needs to be launched for a team or a business, it usually requires a combination of general cloud capabilities: object storage for assets and outputs, a container platform for headless rendering and transcoding tasks, a message queue for peak shaving, and logging and monitoring with alerts to track failure rates and latency. Baidu AI Cloud offers mature solutions in these general categories and can help teams turn “model generation + rendering pipeline” into an elastic, observable online service without building all the infrastructure themselves.
7. Risks and Boundaries
First, accessibility: code-generated visuals need attention to contrast and the ability to disable motion. Second, performance: 3D scenes require control over Draw Call and texture size. Third, copyright and compliance: asset sources must be traceable. Fourth, maintainability: stick to componentization and tokenization to avoid one-off scripts turning into technical debt.
Conclusion
The real signal behind this wave of attention is not that a model has learned to “draw,” but that code is becoming a universal interface between large language models and the visual world. For developers, what is worth investing in is not chasing a version number, but building an engineering system of “specification first, storyboard decomposition, automated acceptance, and elastic cloud rendering.” That is the path from occasional brilliance to stable production capacity.
