LLM Painting with Code: How Simulated Brushes Work in Practice
Large language models can create paintings without calling an image-generation model by writing programs that control a virtual brush. This article explains how stroke-based rendering differs from diffusion, how to structure a simulated painting engine, and how visual feedback supports iterative correction. It also examines style control, engineering trade-offs, and the value of this approach for transparent creative workflows and long-horizon planning.
Introduction: An Alternative to Direct Image Generation
Many mainstream AI image-generation systems use diffusion: starting from random noise, a model progressively denoises an image or latent representation until a complete picture emerges. These systems produce impressive results, but their internal generation process is difficult to interpret. Explaining why a particular pixel appears in a particular location—or intervening precisely in the sequence of creative decisions—is not straightforward.
A different approach asks a large language model (LLM) to write code that moves a simulated brush across a software canvas. Instead of calling an image-generation model, the system builds an image stroke by stroke. The artwork is produced by executing a painting program, potentially thousands of lines long, rather than by directly synthesizing a finished image.
This approach brings planning, execution, and self-correction into a single workflow. It also offers a more inspectable form of AI-assisted creation: the brush instructions can be read, replayed, and reviewed.
This article examines the underlying principles, painting-engine design, implementation structure, and practical considerations.
1. How Code-Based Painting Differs from Diffusion
The key distinction is not simply which model is used. It is how the image is constructed and how the system can intervene during creation.
Different units of generation
Diffusion systems iteratively update an image or latent representation across the frame. Code-based painting instead uses a stroke as its basic creative operation, accumulating marks in sequence.
The first resembles developing a photograph; the second more closely resembles a painter working on a canvas.
Explicit rather than implicit instructions
In diffusion, composition emerges from learned model behavior conditioned on the input. In a painting program, drawing decisions appear as explicit instructions: where to place a stroke, which color to use, how wide the brush should be, and how wet the paint should appear.
These instructions make execution auditable and replayable. They expose what the system did, although they do not necessarily explain every internal reason behind the LLM’s choices.
Correction through additional strokes
Editing a diffusion-generated image often involves inpainting or another model-guided editing operation.
A simulated painting system can instead inspect the current canvas and add strokes to cover, repair, or blend an unsatisfactory area. This resembles a traditional painter’s workflow: earlier mistakes become part of the surface that later marks modify.
Irreversible marks as a creative constraint
Some experimental setups prohibit undoing a stroke after it reaches the canvas. Each committed mark remains part of the painting history.
This constraint encourages more deliberate planning and preserves visible evidence of layering, overpainting, and incidental variation. Those traces can contribute to a more convincing painted appearance.
2. Designing the Simulated Painting Engine
The foundation is a software “studio”: a two-dimensional painting engine that does not require an AI rendering component.
Its core abstractions typically include a canvas, a brush, a stroke representation, and rules for color blending.
Canvas
The canvas is a two-dimensional pixel buffer with optional material properties, such as surface roughness and absorbency.
These properties influence how pigment spreads and how stroke edges form. A rough paper texture, for example, can introduce granular edges instead of perfectly uniform boundaries.
Brush
A brush can be more than a circular stamp. Its state may include:
- Brush width
- Bristle distribution
- Paint load
- Water content, or wetness
- Applied pressure
A wetter brush can produce softer, slightly spreading edges. Low paint load combined with suitable pressure and surface interaction can create broken, dry-brush marks.
Stroke
A stroke combines a path with a sequence of brush states. The path is commonly described using control points, with spline interpolation producing a continuous trajectory.
Small positional variations can make the result less mechanically perfect. Adding a few pixels of jitter may help a line resemble a hand-painted mark, since human movement rarely produces mathematically exact paths.
Color and blending
Each stroke specifies a color, opacity, and blending behavior.
In a wet-on-wet approximation, fresh pigment interacts with paint that has not yet dried, producing softer transitions. A dry-layer approximation creates more distinct overpainting boundaries.
The following conceptual skeleton illustrates the engine’s structure. It is not a complete, runnable implementation: spline interpolation is omitted, and the color conversion referenced by brush.color_hex is not implemented.
import mathimport randomclass Brush:def __init__(self, width, color, wetness=0.5, load=1.0):self.width = width # Brush width in pixelsself.color = color # Color, such as "#30346a"self.wetness = wetness # Wetness from 0 to 1self.load = load # Paint load from 0 to 1class Canvas:def __init__(self, w, h, texture=0.3):self.w, self.h = w, hself.texture = texture # Canvas textureself.pixels = [[(255, 255, 255) for _ in range(w)] for _ in range(h)]def stroke(self, brush, points, jitter=2):"""Draw along path points; jitter approximates small hand movements."""path = interpolate_spline(points)for x, y in path:x += random.uniform(-jitter, jitter)y += random.uniform(-jitter, jitter)self._dab(int(x), int(y), brush)brush.load *= 0.998 # Paint is gradually consumed along the pathdef _dab(self, x, y, brush):r = max(1, brush.width // 2)for dy in range(-r, r + 1):for dx in range(-r, r + 1):if dx * dx + dy * dy <= r * r:self._blend(x + dx, y + dy, brush)def _blend(self, x, y, brush):if 0 <= x < self.w and 0 <= y < self.h:base = self.pixels[y][x]alpha = brush.load * (0.6 + 0.4 * brush.wetness)self.pixels[y][x] = tuple(int(base[i] * (1 - alpha) + int(brush.color_hex[i]) * alpha)for i in range(3))def interpolate_spline(points, step=1.0):# Generate dense path points with spline interpolation; implementation omitted...
More sophisticated engines require substantially richer behavior. In this example, texture is stored but does not yet affect rendering, and wetness only influences blending opacity rather than simulating pigment diffusion.
The central idea remains the same: use explicit physical approximations to make the painting process controllable and inspectable. When randomness is used for texture or jitter, reproducible replay also requires controlling that randomness.
3. The LLM’s Role: Authoring the Painting Program
In this workflow, the LLM does not directly output pixels. It produces a program that calls the painting engine.
A detailed painting may be driven by a program containing roughly one to two thousand lines, with loops expanding those instructions into hundreds of thousands of drawing operations. The exact scale depends on the painting and engine.
The workflow has four main stages.
Step 1: Plan the composition
The model first describes the intended structure, either in natural language or code comments:
- Subject placement
- Light direction
- Overall palette
- Foreground and background relationships
This serves a role similar to a painter’s initial compositional sketch.
Step 2: Build the image in layers
The program follows a broad-to-fine sequence: background before subject, large shapes before details.
Wide brushes establish the background and major color areas. Medium brushes develop the subject’s form and shading. Smaller brushes add highlights, edges, and finishing details.
Code order matters because each operation changes the surface available to subsequent strokes.
Step 3: Inspect and correct
The feedback loop is a defining feature.
The engine renders the current canvas and returns it to a vision-capable model. The model checks for problems—for example, a form that looks too thin or an area with overly busy marks—and writes additional drawing code to address them.
This turns painting from a one-shot output into an iterative process:
Plan → paint → inspect → revise
When undo is prohibited, revisions must work through further marks rather than removing earlier ones.
Step 4: Record and replay
Because every stroke is an explicit instruction, the system can record the progression from a blank canvas to the finished work.
Replaying those instructions can produce a process video, making the intermediate stages useful for both presentation and teaching.
4. Shaping Style Through Persona and Feedback
Explicit control over brush behavior also provides a way to shape artistic style.
In an image-generation model, style is expressed through learned representations and conditioning. In code-based painting, it also appears directly in brush choices, palettes, stroke patterns, and the order of painting operations. Those behaviors can be deliberately adjusted.
This does not make the LLM independent of its training data or automatically resolve questions about artistic imitation. It does, however, make some stylistic decisions easier to inspect.
One approach is to define a fictional painter persona with an artistic background, aesthetic preferences, and favored techniques. That description gives the model a consistent reference across multiple works.
Human feedback can then guide revisions:
- “The shadows need more tonal variation.”
- “The brushwork is too uniform.”
- “The transitions are too sharp.”
The model can respond by changing brush types, wetness defaults, blending rules, or recurring coding patterns.
Over repeated iterations, these choices may form a more stable and recognizable style. This is a feedback-driven refinement process, metaphorically resembling reinforcement learning with natural-language feedback. It is not necessarily reinforcement learning in the technical sense unless a corresponding training procedure is actually used.
5. Engineering Trade-Offs and Suitable Applications
Code-based painting is not a replacement for diffusion. The two approaches serve different priorities.
Cost and latency
A highly detailed painting may require hundreds of thousands or even millions of stroke-simulation operations, plus multiple rounds of visual inspection.
That can make the workflow expensive and slow, particularly when the engine is complex or the model revises the painting repeatedly. It is therefore less attractive for real-time generation or high-volume image production. The actual comparison with diffusion depends on the implementation, rendering settings, and model workload.
Process transparency
A stroke log provides a traceable record of how the image was constructed. This can be valuable in art education and workflows that need documentation of the creative process.
Such a record can support provenance documentation, but it does not by itself establish copyright ownership or originality.
Fine-grained control
Developers can adjust engine parameters to intervene directly in painting behavior. Rather than relying only on a descriptive prompt, they can control specific properties of strokes, materials, and blending.
A test of long-horizon planning
Completing a coherent painting requires the model to manage composition, color relationships, layering, and corrective actions over many steps.
That makes the task a useful setting for examining long-horizon planning and self-correction: locally plausible marks must contribute to a consistent overall image.
Infrastructure requirements
The surrounding architecture can use ordinary cloud infrastructure:
- A container platform runs the painting engine.
- Object storage holds stroke sequences and intermediate frames.
- Logging and monitoring track long-running jobs and failures.
Architecturally, this resembles a batch-processing workload. The main challenge is often the quality of the model’s planning and feedback loop rather than a specialized infrastructure requirement.
Conclusion
Painting through code is more than an unusual image-generation demonstration. It illustrates a broader capability: when an LLM cannot directly produce a desired modality, it can write a program that operates within a simulated environment for that modality.
The painting engine becomes the execution interface. The model plans actions, observes their effects, and revises its program accordingly.
The same general idea extends to areas such as music, 3D modeling, and robotics, although each requires its own execution environment and constraints.
For developers, a small simulated painting engine is an accessible way to explore this pattern. No new model training is required to begin. The essential ingredients are a controllable canvas, a usable brush interface, and a feedback loop that lets the model inspect what its code has actually produced.
