Code-Based Painting: Simulating Brush Strokes Without Calling an Image Model
This article breaks down an alternative image generation approach: instead of calling an image model, a code-capable model writes a drawing program that simulates brush movements on a virtual canvas stroke by stroke. It explains the core mechanism, a minimal stroke instruction structure, the four categories of physical quantities the rendering engine needs to simulate, the multi-round feedback loop, the role of style persona configuration, performance and cost control, a multi-dimensional quality evaluation approach, and the applicable boundaries of this route compared with traditional generation methods.
1. The Starting Question: How Else Can We Paint Without an Image Model
Most mainstream image generation today is built on diffusion models: the model iteratively denoises random noise in latent space, converging into a pixel matrix in one pass or over several steps. The advantage is that the pipeline is end-to-end and fast. The drawback is that the process is hard to interpret, local edits are difficult, and there is no actionable way to fix a specific question like “why did this one line come out crooked.”
The source material describes a clearly different technical route: no image generation model is called at all. Instead, a code-capable model writes a drawing program that simulates the movement of a real brush on a virtual canvas, completing the work stroke by stroke. According to the reported experiment from a research team at a cloud vendor, the model used about 700,000 simulated strokes when drawing a shopping cart in a parking lot; in another experiment, “birds at sunrise,” only 111 strokes were used, and a 21-second record of the drawing process was produced. The contrast between the two cases makes the point clear: stroke count is not a quality metric — planning capability is.
This article abstracts that route into a reproducible engineering framework and fills in the implementation details the original material left out.
2. Core Mechanism: Decomposing “Painting” into Executable Stroke Instructions
The premise that makes this route work is reframing an image from a “result” into an accumulation of “process.” The canvas is not a pixel block generated all at once; it is a state object that keeps being modified. What the model outputs is not an image, but a program that modifies the canvas.
A minimal usable stroke instruction structure can be sketched as follows:
@dataclassclass Stroke:color: tuple[int, int, int] # Paint colorwidth: float # Brush width (pixels)opacity: float # Paint opacitywetness: float # Paint wetness; affects edge diffusionpoints: list[tuple[float, float]]# Path control pointsjitter: float # Path jitter amplitude
The original material mentions an engineering-relevant detail: the first stroke uses a dark blue color, a brush width of 90 pixels, and a path of 5 slightly wobbling control points — the roughly 7-pixel sway is deliberate, because a human arm cannot draw a perfectly straight line. This suggests that realism does not come from resolution but from modeling physical constraints — jitter, pressure changes, paint buildup, and paper fiber absorption are sources of artifacts, and also sources of realism.
3. Rendering Engine: Four Categories of Physical Quantities to Simulate
To make what code draws look “painted,” the rendering layer needs to cover at least four categories of quantities:
- Brush geometry and texture: The distribution of bristles determines the jaggedness and gaps at stroke edges; a bristle brush and a flat brush produce completely different textures.
- Paint transport: Wet paint diffuses on the canvas, while dry paint covers the layer beneath. This can be approximated with a simple diffusion kernel; the higher the wetness, the larger the diffusion radius.
- Canvas texture: A height map of the texture affects the probability of paint adhesion; on a rough canvas, natural skipping (dry brush gaps) appears.
- Drying and layering: A timestamp or dryness value per layer needs to be maintained to decide whether a new stroke blends or covers.
In engineering terms, these are usually split into offscreen buffers and shader stages, submitted stroke by stroke rather than recomputed per frame; otherwise, simulating on the order of 700,000 strokes cannot finish in an acceptable amount of time.
4. Multi-Round Feedback: Letting the Model “Look at the Canvas Before Each Stroke”
The original material emphasizes that the model observes the canvas during multi-round drawing and checks for errors — for example, correcting a bird’s back when it is too thin or lines that are messy. This forms a closed loop:
Plan strokes → Render to canvas → Sample canvas state (thumbnail/local statistics)→ Compare against intent → Generate corrective strokes → Render again
There are three key design points: first, the feedback must be computable — image gradients, edge density, regional color differences — rather than vague self-evaluation; second, corrections can only “add strokes,” not undo, which forces the model to consider irreversibility already during planning; third, context length needs to be controlled, compressing the canvas state into a low-resolution summary plus cropped images of key regions.
5. Style Persona: Trading Text Constraints for a Stable Creative Tendency
The original material notes that early works were criticized for over-imitating existing artistic styles; afterwards, the approach changed to having the model design its own persona with a fictional background and a stable creative style, then tuning brush and engine parameters through textual feedback. In engineering terms, this is equivalent to “maintaining a style configuration in natural language”:
style:palette: [Low-saturation cool tones dominant, a few warm highlights]stroke: Long lines, low jitter, dry-ish edgescanvas: Coarse texture, medium absorbencyhabit: Tends to lay down large areas of base color first, then add details
The style configuration file and the stroke-planning prompts together act as constraints, keeping recognizable consistency across multiple works while avoiding directly replicating the existing vocabulary of a specific artist.
6. Performance and Cost Control
Seven hundred thousand strokes means both rendering and context management must be engineered: batch-submit stroke instructions, update canvas state incrementally, downsample the feedback frequency, and locally repaint failed strokes instead of rerunning the whole image. For longer drawing sessions, stateless rendering tasks can be hosted on a container platform, intermediate canvas snapshots can be saved to object storage, message queues can decouple stroke production from rendering consumption, and logging services with monitoring alerts can track per-round latency and failure rates. These are all general cloud capability categories; specific choices should be evaluated according to scale.
7. Quality Evaluation: Don’t Use “Does It Look Like a Photo?” as the Only Criterion
At least four dimensions are recommended: structural correctness (proportions and placement of the subject), stroke reasonableness (whether meaningless repetition exists), style consistency (how well the configuration matches across works), and controllability (whether textual feedback reliably takes effect). Controllability is the most easily overlooked, yet it determines whether this approach can enter a production workflow.
8. Applicable Boundaries
The strengths of code-simulated painting are an interpretable process, locally modifiable results, and programmable style; the weaknesses are output speed and the convergence cost of hyper-realistic detail. It is better suited to scenarios that need a traceable creative process, precise local control, or batch consistency in a unified style; for businesses that pursue millisecond-level output, traditional generation approaches are still the choice. The two routes are not substitutes but trade-offs made according to constraints.
