Code-Driven AI Painting: How Large Models Simulate Real Brushstrokes
This article examines an emerging paradigm in generative AI: code-driven painting, in which large language models create images by generating step-by-step drawing instructions—simulating real brush movements, paint behavior, and canvas texture—rather than relying on diffusion models. It compares the two approaches, breaks down the core components of a realistic painting simulation engine, explores how models plan stroke sequences and self-correct through visual feedback, and discusses the practical value, technical challenges, and deployment considerations of this technique. The article is intended for AI developers, technical architects, and engineering leaders interested in structured generation, explainable AI, and multi-step decision-making systems.
Introduction: When Large Models Learn to Hold a Brush
In the field of generative AI, image creation has long been dominated by diffusion models—algorithms that start from random noise and, through iterative denoising steps, produce a complete image at once. Recently, however, a fundamentally different approach has emerged: instead of calling an image generation model, large language models (LLMs) produce artwork by writing code that simulates the trajectory of a real paintbrush on a virtual canvas, tracking brush movement, paint state, and canvas texture layer by layer.
This capability demonstrates a new paradigm that combines code generation with visual creativity. In one public demonstration, a leading large model created a near-photorealistic image using roughly 700,000 simulated brushstrokes. In another experiment, the model completed a sunrise scene with birds in just 111 strokes, independently planning the coordinates, color, and brush width of every single stroke. This article systematically unpacks this paradigm from four angles: technical principles, engine design, planning strategies, and engineering practice.
1. The Fundamental Difference Between Two Generation Paradigms
1.1 Diffusion Models: Statistical Emergence
Most text-to-image tools today are built on diffusion models. The core mechanism works like this: the model learns the reverse process of adding noise to an image, gradually removing noise in latent space, and outputs a complete pixel-level result in a single pass. This approach offers fast generation and rich visual detail, but it comes with inherent limitations:
- Lack of interpretability: Since the image emerges as a whole, it is impossible to answer “why was this stroke placed here?”
- High cost of modification: Local edits typically require full regeneration or special inpainting mechanisms.
- No creative process: There is no temporal sequence of drawing steps, making it difficult to review or teach the creation process.
1.2 Code-Driven Painting: Procedural Brush-by-Brush Construction
Code-driven painting, by contrast, decomposes creation into a large number of individual brushstroke instructions. The model acts as a “painter” rather than a “printer”: it first visualizes the overall composition, then plans the order of strokes, and finally controls a virtual brush through code to execute each stroke one by one. Each instruction typically contains the following elements:
stroke = {"brush": "round_flat", # brush type"color": "#30346a", # pigment color hex code"width_px": 90, # brush width in pixels"wetness": 0.65, # paint wetness level"path": [(x1, y1), (x2, y2), (x3, y3), ...], # path control points"pressure": [0.8, 1.0, 0.6], # segmented pressure values}
The essential difference is this: the model outputs not pixels, but creative decisions. The image itself is merely a by-product of those decisions rendered through the simulation engine.
2. Core Design Elements of a Painting Simulation Engine
To make stroke-by-stroke painting look realistic, the underlying engine must simulate the physics and behavior of real painting to a high degree. While implementations vary, industry experience suggests that such an engine should cover the following capabilities:
2.1 Brush Physics Modeling
The edge of a real brushstroke is not a geometrically perfect line. It contains hair splits, paint accumulation, and dry-brush effects. Engines typically model brush shapes parametrically—round, flat, fan-shaped, and so on—and dynamically adjust paint deposition based on pressure and stroke speed.
2.2 Wet Paint and Color Mixing
Wet-on-wet painting is a key technique in real painting. The engine must track the moisture level of paint already deposited on the canvas: when a new stroke lands on a still-wet area, the colors diffuse and blend rather than simply layering on top. This forces the model to account for an implicit constraint—“waiting for the paint to dry”—when planning the sequence of strokes.
2.3 Canvas Texture and Media Absorption
The texture of the canvas affects the microscopic appearance of each stroke. By applying surface normal perturbation and absorption maps during rendering, digital strokes can take on the tactile quality of paper or linen canvas, significantly enhancing the “hand-painted” feel of the final output.
2.4 The Non-Undo Constraint
One particularly notable design choice is that strokes cannot be undone once applied. This forces the model to plan carefully, just like a human painter—if a mistake is made, it can only be corrected with new, covering strokes rather than rolled back. This constraint actually produces a more realistic creative process: the traces of correction become part of the work itself.
3. Planning Strategies of Large Models for Painting
3.1 Hierarchical Composition: From Global to Local
Experiments show that models tend to follow the layered logic of classical painting instruction: first using wide brushes to lay down broad color blocks that establish the lighting and tonal relationships, then gradually switching to smaller brushes for detail work. In the 111-stroke bird example, the first stroke used a 90-pixel-wide brush to establish the canvas’s overall tone, and subsequent strokes decreased in width progressively.
3.2 Deliberate Imperfection
An interesting detail: the model intentionally added random jitter of about 7 pixels to its straight-line paths, on the grounds that “the human arm cannot draw a perfectly straight line.” This demonstrates an understanding that the source of realism lies in controlled imperfection—mathematically perfect lines are precisely what reveal the output as machine-generated.
3.3 Visual Feedback and Self-Correction
During multi-pass drawing, the model “observes” the current state of the canvas (typically by passing the image back to the model’s visual understanding capability) and checks proportions, structure, and color accuracy. For example, if it finds that a bird’s back is too thin or that lines are chaotic, it applies corrective covering strokes in the next round to widen the shape and unify the direction. This close-the-loop process of “draw–observe–correct” is a capability that does not exist in traditional text-to-image pipelines.
4. Style Consistency and Persona Design
Early experiments in this area suffered from artworks that overly imitated existing artistic styles. One effective improvement: have the model first construct a fictional “artist persona”—including their training background, preferred subjects, and signature techniques—and then create under the constraints of that persona. Through iterative text feedback, researchers refined brush parameters and engine behavior so that the resulting style became stable and original.
This practice holds a general lesson for engineering applications: when a generative system needs to produce style-consistent output, explicit character design and constraints often work more effectively than blind parameter tuning.
5. Value and Challenges in Engineering Deployment
5.1 Potential Value
- Interpretability: Every step is an auditable code instruction, suitable for teaching, design provenance, and similar scenarios.
- Editability: Since the artwork is essentially a parameterized program, changing a stroke means adjusting the corresponding instruction.
- Reusable capability: The same “plan–execute–feedback” framework can be transferred to structured creation tasks such as vector illustration and process-flow generation.
5.2 Real-World Challenges
- Computational cost: At the level of 700,000 strokes, the inference and rendering overhead is enormous—far exceeding a single diffusion pass.
- Context management: In long-sequence creation, the model must continuously track the canvas state, which places high demands on both context windows and visual understanding.
- Engine complexity: Building a realistic painting engine requires deep expertise in computer graphics and color science.
In practical deployment, such long-running inference workloads can be supported on general-purpose cloud infrastructure: container platforms can orchestrate rendering tasks, object storage can manage intermediate canvas states, and monitoring and alerting services can track generation progress. Cloud platforms offering general-purpose compute and storage—such as Baidu AI Cloud—provide flexible elastic support for this class of high-throughput generative workloads.
Conclusion
Code-driven painting represents an important branch point for generative AI. Rather than aiming for one-pass pixel output, it teaches models to learn the process of creation. Although it cannot yet compete with diffusion models in efficiency, its interpretability, editability, and process-oriented nature open new possibilities for AI-assisted creation. For developers, understanding the three-stage architecture of “decision generation + physical simulation + visual feedback” may hold more long-term value than following any specific model release.
