Painting Without an Image Model: Simulating Brushstrokes with Code

    This article explores an alternative to text-to-image generation: instead of relying on a diffusion model, an LLM writes a program that simulates a brush, paint, and canvas, drawing a complete image one stroke at a time. It compares the two paradigms, breaks down the physics of the brushstroke engine (brush path, paint mixing, canvas texture, and deliberate imperfection), and provides sample code for parameterizing and compositing a single stroke. It then explains the multi-round paint–observe–correct loop with structured feedback, followed by engineering guidance on performance, reproducibility, and stylization. Readers will learn how code-based painting delivers traceable, editable, and reproducible artwork, and how it can be combined with diffusion models rather than replacing them.

    1. Introduction: Images Can Be Computed, and They Can Be Painted

    Text-to-image technology has matured considerably over the past two years. Diffusion-based approaches start from random noise, iteratively denoise in a latent space, and then use a decoder to reconstruct a pixel image. A short prompt is enough to produce a high-quality image. But these methods are black boxes: the final output is a single result of probabilistic sampling. It is difficult to intervene in a particular contour, a specific patch of light and shadow, or the direction of a single stroke, and there is no way to review stroke by stroke how the image took shape.

    Recently, an engineer’s published experiment demonstrated a fundamentally different approach: without relying on any image generation model, an LLM is asked only to write a program that simulates the interaction between brush, paint, and canvas on a virtual canvas, drawing a complete picture one stroke at a time. According to the experimenter, one photorealistic piece—a shopping-cart parking lot—took roughly 700,000 strokes, with 1,000 to 2,000 lines of program code; another piece, “A Bird at Sunrise,” used only 111 strokes, and the whole process was recorded as a 21-second video.

    These two data points make a shared point: a single “good” stroke does not come from stacking a large number of strokes. Three things actually matter: modeling the physics of the brush, a closed loop of multiple “paint–observe–correct” rounds, and deliberately introducing imperfection. The sections below break down the technical principles and offer an implementable approach.

    2. Two Generation Paradigms: Iterative Denoising vs. Stroke-Sequence Decision

    Dimension Diffusion model path Code-simulated brush path
    Unit of generation The whole image (latent representation) A single brushstroke, combined into a full picture
    Generation process Iterative denoising Stroke-sequence decision, composited stroke by stroke
    Intermediate artifact Latent variables An executable painting program and a stroke log
    Editability Local inpainting Any stroke can be modified or replayed individually
    Output cost Mainly image-model inference LLM inference plus rendering computation
    Source of uncertainty Sampling randomness Model strategy stability, accumulated stroke error
    Typical problems Composition drift, loss of detail Redundant strokes, muddy colors, long-range drift

    Code-based painting can be viewed as a sequential decision problem in a canvas environment:

    • State: the current canvas content and the accumulated intent of prior strokes.
    • Action: laying down a stroke that carries parameters such as stroke type, color, width, path points, and wetness.
    • Feedback: after painting, observing the canvas and comparing the difference between the target and the current image.

    A diffusion model treats each denoising step as a small correction to the entire image, and the final step decodes all pixels at once. Code-based painting pushes the decision down to the stroke level, then uses a deterministic rendering engine to compute the parameters into pixels.

    The direct benefit of this shift is that the process is transparent and replayable. Every stroke has a structured record; it can be re-rendered and adjusted by parameter, and can be placed under version control together with the rendering engine. The cost is that the model must maintain global planning on its own, and controlling long-range consistency and accumulated error becomes significantly harder.

    3. The Brushstroke Engine: Simulating Brush, Paint, and Canvas

    The brushstroke engine is the physical foundation of the entire approach. Taking oil-type paint as an example, real painting involves at least four interacting elements.

    1. Brush and path

    • A path is usually described by several control points and then interpolated into a smooth curve. Spline curves are commonly used; in the published experiment, a single stroke used 5 slightly wobbling path points.
    • Brush speed affects how heavy the stroke lands: faster means a thin, faint line; slower means paint piles up and the line becomes thick and dense.
    • A bristle brush has multiple bristles that produce uneven ink pickup, creating textures such as dry-brush streaks and brush marks.

    2. Paint and mixing

    • Opaque mixing: opaque paint “covers” the layer beneath rather than blending optically. This kind of color mixing is often described physically with Kubelka-Munk theory.
    • Translucent layering: in engineering practice, a weighted average in linear light space is commonly used as an approximation. If alpha blending is done directly in sRGB space, dark regions tend to turn gray and contrast drops.
    • Color-sampling strategy: it is normal for the overall color to grow grayer as layers accumulate. Real painters relight areas at any moment with a clean, light color, and the generation program needs the same “highlight stroke.”

    3. Canvas and paper

    The texture of paper or canvas affects the penetration and diffusion of paint through absorption; a program can use a height field to simulate fiber relief, letting paint deposit more in the uneven areas.

    4. Deliberate imperfection

    In the published case, the model designed a slight wobble of about 7 pixels for the first stroke. The model’s reasoning: a human arm cannot draw an absolutely straight line, and a perfect straight line instead looks “not human-drawn.” This kind of perturbation should be a configurable parameter (such as jitter amplitude or a pressure random seed), not an incidental floating-point error. Otherwise, replaying the same code twice would yield two different images.

    4. Sample Code: Parameterizing and Compositing a Stroke

    The pseudocode below shows the stroke data structure and the compositing flow (rendering details omitted):

    1. from dataclasses import dataclass, field
    2. @dataclass
    3. class Brush:
    4. """Brush parameters: geometry, pigment, and physical properties."""
    5. kind: str = "flat" # Brush type: flat / round / fan
    6. color: str = "#30346a" # Pigment color
    7. base_width: float = 90.0 # Brush width (pixels)
    8. flow: float = 0.7 # Ink flow: higher means more opaque
    9. wetness: float = 0.3 # Paint wetness: affects edge bleed and layering
    10. jitter_px: float = 7.0 # Jitter amplitude: simulates human imperfection
    11. bristles: int = 1 # Number of bristles: >1 produces streaks and dry-brush texture
    12. @dataclass
    13. class Stroke:
    14. """One stroke = brush + path + per-point pressure. Every field is written to the stroke log."""
    15. brush: Brush
    16. points: list = field(default_factory=list) # Control points [(x, y), ...]
    17. pressure: list = field(default_factory=list) # Per-point pressure, range 0~1
    18. def render_stroke(canvas, s: Stroke):
    19. """Render a single stroke onto the canvas. Core steps: smooth -> pressure -> brush texture -> pigment compositing."""
    20. path = smooth_path(s.points, s.brush.kind) # Spline-interpolate into a smooth path
    21. for p in path:
    22. w = s.brush.base_width * pressure_at(s, p) # Pressure determines stroke width
    23. # Sample ink evenly across the brush width, instead of drawing a solid line
    24. for d in sample_dabs(w, spacing=w * 0.1):
    25. color = pick_color(s.brush.color, p, d) # Color shift from wet/dry and bristles
    26. # Alpha composite in an approximately linear-light space to avoid grayish dark overlays
    27. canvas.blend(p + d, color, alpha=s.brush.flow)
    28. # Wet edge: add a thin, darker layer of paint along both sides of the path to simulate water marks and pigment buildup
    29. if s.brush.wetness > 0:
    30. canvas.add_wet_edge(path, w, s.brush.wetness)

    The design highlights are as follows:

    1. A stroke is a piece of structured data: the brush, path, and pressure are all recorded explicitly. After painting finishes, the stroke log itself is a replayable, versionable asset.
    2. The brush tip samples in a “stamping” manner: sampling evenly across the brush width, combined with bristle offsets, automatically yields a stroke rich in texture.
    3. Compositing happens in linear light space: the comparison experiment is as follows. The same blue composited over orange at 0.5 opacity gives a result of about (168, 139, 99) in sRGB space and about (193, 133, 70) in linear light space. The latter is closer to how watercolor and oil paint actually mix.
    4. Rendering is decoupled from storage: the canvas interface can point to an image file in memory or in object storage, or to a large canvas rendered in tiles. The stroke log and the rendering result are written to disk separately, making later re-rendering or parameter tuning easier.

    5. Multi-Round Paint–Observe–Correct: Let the Model See Its Own Work

    The brushstroke engine solves “how to paint”; closed-loop feedback solves “whether it looks right.” A typical loop looks like this:

    1. def paint(renderer, plan_strokes, check, goal, rounds=3, fix_budget=20):
    2. for rnd in range(rounds):
    3. for s in plan_strokes(rnd):
    4. renderer.apply(s) # Once laid down, a stroke cannot be undone; it can only be corrected by a new stroke
    5. renderer.log(s) # Log the stroke for review and replay
    6. report = check(renderer.snapshot(), goal)
    7. if report.ok:
    8. break
    9. # Guide the next round with a structured issue list: issue -> cause -> fix action
    10. plan_strokes(rnd + 1, report.issues[:fix_budget])
    11. return renderer

    In the published case, the model observed that the bird’s back was drawn too thin and the lines were messy, so in later rounds it used new strokes to deepen, thicken, and straighten the contour. This is exactly the oil-painting logic of correction: instead of erasing a mistake, you cover the previous stroke with a new one.

    For this mechanism to run reliably, three points are worth noting.

    1. Feedback must be structured

    Feedback should be a list shaped like “issue → possible cause → fix action,” not a vague “it looks bad.” For example:

    1. {"part": "the bird's back", "issue": "thin and messy lines", "cause": "strokes too thin, path jitter too large", "fix": "deepen the color and retrace the contour with a wider round brush"}

    This turns a fuzzy quality judgment into an explicit adjustment of brushstroke parameters.

    2. The multi-round loop needs stopping conditions

    You can use a triple constraint of “error threshold + maximum rounds + cap on fix strokes per pass” to avoid getting stuck endlessly on local details. Comparing the canvas against the goal stroke by stroke on metrics such as color, edge gradient, and structural similarity turns “does it look right” into a quantifiable objective.

    3. Observation cost and correction strategy must be balanced

    Rendering the canvas into an image and handing it to a multimodal model for visual judgment can simulate the process of “a painter stepping back a few steps to look at the work,” but each round adds inference overhead. Feasible strategies:

    • Layer by layer, then local: advance in stages such as “block in large color areas → shape the mid-ground → finish the details”; in early stages focus only on composition and light/shadow, and handle texture later.
    • Quantitative first, then qualitative: for high-frequency stroke loops, use quantitative metrics for coarse filtering, and invoke visual judgment only on local regions.
    • Prefer local correction: limit the correction scope to the problem area, avoiding global side effects and reducing wasted strokes.

    6. Engineering in Practice: Performance, Consistency, and Stylization

    1. Performance: stroke count determines the cost structure

    Hundreds of thousands or more strokes mean a large number of small drawing operations, whose time cost is far higher than whole-image inference:

    • Use small brush caches instead of repeatedly creating brushes per stroke.
    • Render a low-resolution sketch first to quickly validate composition, then render at full resolution once the design is finalized.
    • Distribute different layers across multiple rendering processes to run in parallel, scheduling tasks through a queue, hosting them in containers, and collecting latency and failure rate per instance.

    2. Consistency: replay should produce the same image

    The stroke log is the core asset, and randomness must be controlled. Random quantities such as jitter and pressure sampling should be generated from a fixed seed and written into the log; the rendering engine version and the color management strategy (color space, gamma handling) should also be versioned together with the code. Otherwise, replaying the same code in a different environment will produce visibly different results.

    3. Stylization: from “imitation” toward a “stable persona”

    Early painting attempts drew discussion for imitating existing artistic styles too closely. In later experiments, an engineer had the model design an “artist” persona with a fictional background and stable creative tendencies, then used textual feedback to guide it in adjusting the brush and engine.

    This is essentially a structured style constraint: first define dimensions such as color preference, brushstroke rhythm, and light/shadow contrast, then validate against quantifiable style rules. This both gives the work a recognizable identity and avoids the copyright and ethical risks of directly imitating a specific artist.

    7. Practical Recommendations: Complementary Capabilities, Not Replacement

    Code-simulated brushwork and diffusion models are complementary. For photorealistic rendering, diffusion models still hold advantages in high-frequency detail, material representation, and generation efficiency. The advantages of code-based painting lie in:

    • Traceability: every stroke has a structured record.
    • Intervenability: any stroke can be modified or replayed individually.
    • Easy integration: programmatic assets naturally fit into rendering pipelines, batch jobs, version control, and monitoring and alerting systems.

    In practice, a hybrid strategy works well: use a diffusion model to quickly generate a composition sketch, then let the programmatic brushstroke engine handle controllable coloring, line redrawing, and style unification. This preserves generation efficiency while gaining editability at the stroke level.

    For teams that want to try this, the recommendation is to start with the pressure and color-mixing module of a single brush, then gradually expand to multiple layers, multiple brushes, and closed-loop correction, using a replayable, quantifiable stroke log as the acceptance criterion at each stage. What truly determines image quality has never been merely the number of strokes, but whether each stroke lands in the right place with the right color and force.