Stroke-by-Stroke Painting with Code: How LLMs Draw Without Image Generation Models
A recent set of "AI paintings" achieved striking results without calling any image generation model: a photorealistic shopping cart in a parking lot that reportedly required around 700,000 simulated brushstrokes, and a minimalist "Bird at Sunrise" finished in just 111 strokes, with the whole process condensed into a 21-second drawing video. Both share a defining trait—neither used any image generation model. Instead, a next-generation coding LLM writes Python scripts that describe each stroke's position, color, and shape, and a simulated painting engine renders them onto a virtual canvas one stroke at a time. The model acts as a painter, not a pixel generator, handling three tasks: understanding creative intent, planning each stroke, and revising based on the rendered result. This article uses these cases to break down the core principles, key stages, and engineering practices of this technical approach.
Lately, a distinctive set of “AI paintings” has been circulating on social media. One, a shopping cart in a parking lot aiming for photorealism, reportedly took around 700,000 simulated brushstrokes to complete. Another, “Bird at Sunrise,” was finished in just 111 strokes, with the entire process compressed into a 21-second drawing video. They have one thing in common: neither called any image generation model.
According to media reports, a researcher at a lab demonstrated a capability that emerges when working alongside a next-generation coding LLM. The model writes a Python script that describes the position, color, and shape of each stroke, and a simulated painting engine then renders those strokes onto a virtual canvas one at a time. The pixels on the canvas come from the renderer. The LLM plays not a “pixel generator” but a “painter.” Its job can be summarized in three things: understanding the creative intent, planning each stroke, and continually refining based on the visual result.
This article uses this set of cases as a thread to unpack the core principles, key stages, and engineering practices behind this technical path.
1. Two Technical Paths: Diffusion Generation vs. Stroke-Level Procedural Drawing
Diffusion Generation: “Reconstructing” an Image in Latent Space
Most mainstream image generation tools are built on diffusion models. During training, the model learns how to progressively add noise to a clear image; during generation, it starts from random noise and repeatedly denoises to produce a complete image in a single pass. This path has clear advantages:
- Rich visual detail: Pixel-level texture and lighting relationships emerge naturally through holistic optimization;
- Efficient, parallel generation: A finished image comes out of a single inference;
- Relies on large-scale image-text data: This gives the model strong semantic understanding.
But it also has some inherent limitations: users find it hard to precisely intervene in local regions of an image, and problems like “an extra hand” require additional patching; re-running the same prompt often yields a different result; and what the model actually drew can only be judged indirectly, through the final image.
Stroke-Level Procedural Drawing: Handing Painting Over to a Rendering Engine
Procedural drawing follows a completely different division of labor:
- The LLM outputs only structured stroke descriptions;
- The rendering engine is responsible for actual image formation.
The model’s work amounts to breaking a painting into a sequence of instructions—brush type + color + width + path points—then handing them to an engine that simulates the physical behavior of brushes for stroke-by-stroke execution. In the bird experiment mentioned earlier, the first stroke used color #30346a (a deep blue-violet, understood as the residual twilight before sunrise), a brush width of 90 pixels, and 5 path points with slight wobble. The model explained that the roughly 7-pixel sway was deliberate, because a human arm cannot draw a perfectly straight line.
The differences between the two paths can be summarized as follows:
| Dimension | Diffusion Generation | Stroke-Level Procedural Drawing |
|---|---|---|
| Image formation | Model predicts pixels directly | Model outputs instructions; the rendering engine forms the image |
| Generation granularity | Whole image generated simultaneously | One instruction per stroke, accumulated progressively |
| Controllability | Prompt-level; weak local intervention | Position, color, and brush parameters are all adjustable |
| Editability | Hard to modify a single element | Can locate, replace, or append by stroke |
| Compute cost | A finished image from a single inference | Multiple rounds of generation + rendering; cost grows with iterations |
| Source of texture | Pixel-level detail emerging naturally | Physical simulation of brushstrokes and pigment |
It’s worth noting that this is not a simple “new versus old” contest. Diffusion models excel at overall atmosphere and rich detail, while procedural drawing excels at controllability, explainability, and media texture. The two have complementary technical value.
2. Overall Architecture: A Closed Loop of Plan, Execute, Observe, Revise
To make the model “paint like a painter,” the core is to transform one-shot generation into a multi-round “plan–execute–observe–revise” closed loop. The whole system can be divided into five layers.
The Creative Planning Layer
This layer converts user requirements into an executable creative plan, including:
- Composition (subject position, perspective, aspect ratio);
- Direction of light and shadow;
- Dominant color palette and light-dark distribution;
- Brushstroke strategy (laying down base color, drawing outlines, adding light and shadow, detailing).
The planning result runs through all subsequent rounds as context. Otherwise, the model would have to re-decide “what to draw” every round, and the style and structure would easily drift.
The Stroke Generation Layer
This layer decides the brush type, color, width, path points, and motion for each stroke, and outputs structured instructions. A stroke description can be illustrated with a data class:
from dataclasses import dataclass, field@dataclassclass Stroke:brush_type: str # brush type: round / flat / dry, etc.color: tuple[int, int, int] # RGB color, e.g. (48, 52, 106)width: float # brush width (pixels)points: list[tuple[float, float]] = field(default_factory=list) # stroke path pointsjitter: float = 0.0 # path jitter amplitude (pixels)wetness: float = 0.5 # pigment wetness (0 dry ~ 1 wet)def paint(engine, strokes: list[Stroke]) -> None:for stroke in strokes:engine.apply(stroke) # the rendering engine draws stroke by stroke
Here, jitter and wetness directly determine texture:
- jitter: Adds slight perturbation along the stroke path. A perfectly straight line is a hallmark of machine-like output; moderate jitter is actually closer to a real human hand.
- wetness: Controls how pigment spreads, seeps, and blends. Dry brushes suit dead branches, fur, and matte textures, while wet brushes suit large blocks like skies and water.
The Rendering Execution Layer
The rendering engine handles “physical simulation” and must balance limited compute against rendering time. The following simulations are particularly important:
- Brush texture: Stiff and soft brushes deposit ink differently. A real brush carries limited pigment per stroke, so the ink should fade from thick to thin within a single stroke;
- Pigment mixing and stacking: Transparent pigments should blend when layered, while thick paint should cover the layer beneath. If “overwrite” mode is always used, the image tends to look gray and muddy;
- Canvas texture: Grain and absorbency affect edge sharpness and how far color spreads;
- Determinism: The same input must produce the same output. Only when rendering is reproducible do the model’s trial-and-error and comparison become meaningful.
The Observation and Diagnosis Layer
This layer “looks back at the canvas”:
- Generate a fixed-ratio thumbnail of the canvas as visual input for a multimodal model;
- Assess whether composition, proportions, light and shadow, and color scheme deviate from the target;
- Produce a structured diagnosis, such as “the bird’s back line is too thin and looks messy” or “insufficient contrast between subject and background.”
The Correction and Termination Layer
This layer generates additional strokes based on the diagnosis and decides when to stop drawing. The real difficulties lie in “what to evaluate” and “when to stop”:
- Too many diagnostic dimensions: Correcting proportion, light and shadow, and texture all at once creates conflicts that make the model messier with each revision;
- No termination condition: Without a clear target description or quantitative metric, the model may endlessly “refine,” wasting compute and degrading the image;
- Convergence strategy: In practice, a “multi-round iteration + stop when marginal gains diminish” approach works well. Record the image difference each round; when the improvement a single round can bring shrinks noticeably, end the drawing.
3. Case Analysis: Two Works Reveal the Design Trade-offs
The Photorealistic Shopping Cart: Trading Stroke Volume for Realism
According to a lab employee, the shopping cart painting aiming for photorealism involved around 700,000 simulated brushstrokes. It most likely came from a parameterized painting program rather than 700,000 lines of hand-written code. A typical program is only 1,000 to 2,000 lines; the actual strokes are mass-produced by parameterized brushes, batch drawing interfaces, and loop logic. The model is responsible for stroke rules and parameter distributions, while the rendering engine handles execution.
This kind of work relies on no external image model and uses neither pre-rendered nor traced base images; the result comes entirely from the program the model wrote. The engineering takeaway is: abstract “large-scale repetitive operations” into “parameterized rules.” First cover most strokes with a few rules, then refine specific regions. This dramatically lowers generation cost and makes it easy to keep a consistent style.
The 111-Stroke Bird: A “Less Is More” Aesthetic Under Constraints
In the bird experiment, the researcher set two strict constraints for the model:
- The brush’s physical properties, wet pigment, and canvas texture could only be simulated through code;
- Each stroke had to be output separately as a coordinate instruction, and once laid down, it could not be undone.
The finished painting used just 111 strokes. The 21 seconds is the length of the video presentation, not the actual rendering time. The value of constraints lies precisely in forcing trade-offs: less is more. A limited number of strokes forces the model to focus on the skeleton and key details rather than piling up texture with countless strokes. Many “AI-looking” images suffer from over-stacked detail with no clear hierarchy, and a lower stroke count actually comes closer to the aesthetic of a sketch or watercolor.
Reversible vs. Irreversible: A Fundamental Difference in Interaction Models
Professional drawing software usually offers unlimited undo, letting digital artists experiment boldly. Stroke-based drawing, once a stroke is down, can only make “additive” corrections. The fundamental difference lies in undo capability:
| Capability | Reversible digital canvas | Stroke-based drawing (irreversible) |
|---|---|---|
| Correction method | Rollback, erase, layer adjustment | Cover, add layers, append strokes |
| Fault tolerance | High; suited to exploration | Low; requires thinking before committing |
| Generation constraint | Weaker | Stronger; closer to real painting |
Because of this, such systems demand far more from “upfront planning” than traditional drawing tools, and they better test a model’s planning and reasoning ability.
4. The Self-Correction Mechanism: Letting the Model “See” Its Own Mistakes
“Observing the canvas and checking for errors” may seem like just an extra glance at the result, but behind it is a closed-loop control system that can be likened to a “generate–simulate–verify–correct” R&D paradigm:
- The stroke instructions are the “design” the model submits;
- The rendering engine is the “simulation,” turning the design into observable results;
- Visual diagnosis is “verification,” answering “does the current image match the design intent?”;
- Corrective strokes are “iteration,” approaching the goal without starting over.
The following illustrative code describes this loop:
def draw_with_feedback(model, canvas, target, max_rounds=10):strokes = []best_score = evaluate(canvas, target)for round_id in range(max_rounds):# 1. Use the current image and the creative goal as input to diagnose problemsissues = model.diagnose(canvas.thumbnail(), target, strokes)if not issues:break# 2. Generate corrective strokes for the problems (append only, no undo)fixes = model.plan_fixes(issues, strokes)paint(canvas.engine, fixes)strokes.extend(fixes)# 3. Evaluate: keep if improvement is clear, terminate if gains diminishscore = evaluate(canvas, target)if best_score - score < THRESHOLD:breakbest_score = scorereturn canvas, strokes
The loop has three key design points:
- Separate diagnosis from drawing: First pin down the problem, then make changes, avoiding the back-and-forth smearing that comes from “thinking while painting”;
- Correct with history in mind: Corrections must account for the existing stroke distribution, otherwise the model tends to stack repeatedly in the same spot, letting pigment pile up and turn muddy;
- Quantified termination condition: Stopping based on “amount of improvement” rather than “number of rounds” better matches the creative habit of “revising until satisfied.”
In addition, human painters are good at stepping back to observe the whole picture, switching back and forth between local and global views. Giving the model a dual perspective of “thumbnail observation + detail zoom” can also help it spot proportion and composition problems that are hard to catch by looking at the local area alone.
5. Style Shaping: Avoiding Sameness with an “Artist Persona”
According to that employee, some paintings by a previous-generation coding model from the same lab were criticized for overly imitating existing artistic styles. This reflects a common problem: models tend to apply the most common style templates from their training data, resulting in low recognizability and unstable style.
To address this, the researchers adopted a new approach:
- A fictional artist persona: Assign the model an “artist” with a fictional background, creative philosophy, and preferences, so that all works are produced under this persona;
- Stable style: Guide the model to adjust brushes and the painting engine through text feedback. For example, pointing out “this batch’s colors are grayer than the last” leads the model to modify its palette and color-usage rules;
- Cross-work consistency: The persona should cover dimensions such as color preferences, brush choices, composition habits, and subject preferences, so that style is baked into the stroke parameters rather than being just a one-line style description.
From an engineering standpoint, the persona is essentially an “executable style configuration.” It converts abstract style constraints into concrete parameter constraints, and it is reproducible, evolvable, and version-controllable. This has direct relevance for scenarios that need visual consistency, such as series illustrations and brand visual extensions.
6. Capability Boundaries and Applicable Scenarios
Objectively, stroke-based drawing is not superior to diffusion generation in every scenario.
Scenarios where it excels:
- When controllability and editability are needed: Scientific illustrations, engineering diagrams, data visualizations, and other graphics that require precise elements and verifiable content;
- When emphasizing media texture: Stylized work in watercolor, oil painting, sketch, and similar styles;
- For showcasing and teaching the creative process: Every stroke is traceable, and the drawing process can be used to explain brushwork.
Its limitations:
- High compute cost: One instruction per stroke means multiple rounds of generation and rendering. Works on the order of 700,000 strokes are demanding on both compute and time;
- Weaker overall semantic grasp: Complex figures and fine textures still require pixel-level modeling; the model struggles to fully convey them through stroke descriptions alone;
- Depends on the quality of physical simulation: If the engine represents brushstrokes and pigment poorly, the result becomes mechanical repetition.
A more realistic way forward is to combine the two:
- Use an image model to generate sketches or composition references as the “conception stage” of creation;
- Then have a coding model break the reference into stroke instructions to realize an editable “drawing stage”;
- Also let the image model act as an “art director,” scoring the rendered result across dimensions like composition, light and shadow, and color to drive the correction loop.
7. Engineering Implementation Guidance
If you want to build similar capabilities into your own system, the following practices are worth referencing:
- Determinism and reproducibility: Fix the random seed, and record stroke instructions, engine version, and model version. Every work should be able to “replay” its image;
- Layered rendering and caching: Split the canvas into base-color, subject, and detail layers, redrawing only the parts that changed to reduce per-round rendering cost;
- Cost estimation and budget control: Estimate the number of strokes and iteration rounds from the target precision, and set a maximum iteration count and a per-task time limit;
- Persist stroke instructions: Save works as structured instructions, which supports later editing and re-creation and makes it easier to analyze the model’s creative patterns;
- Leverage general cloud capabilities: Rendering tasks can run in containerized environments that scale elastically; works and intermediate results can be stored in object storage; and model calls and rendering logs can feed into logging and monitoring/alerting services for easier troubleshooting and cost accounting;
- Human-machine collaboration: Introduce human review at key points, letting creators give feedback in natural language so the model can “understand the feedback.”
Conclusion
The significance of “painting with code” is not in proving that “you can draw without calling an image model,” but in offering an entirely new generation paradigm. The model shifts from being a “predictor of pixels” to a “decision-maker of strokes,” and the creative process gains explainable, editable, and reproducible qualities.
For developers, the most valuable thing to take away from this path is the general methodology it embodies:
- Replace black-box output with structured representation;
- Replace one-shot generation with closed-loop feedback;
- Use explicit constraints to force trade-offs;
- Use a stable persona to accumulate style.
These ideas apply equally to code generation, simulation design, automated testing, and other tasks. Letting the model keep iterating within a loop that is “observable, verifiable, and correctable” is precisely the key step for intelligent coding tools to move from “generating code” to “delivering results.”
