Programmatic Painting Without Image Models: Simulating Real Brushes with Code

    This article examines an alternative to diffusion-based text-to-image generation: using a code-capable large language model to write an executable painting program that places individual brushstrokes on a virtual canvas. It explains the core ideas of separating planning from rendering and using an observation-correction loop; describes a five-layer system architecture, from intent and style planning to run and export; discusses brush, pigment, canvas, and path simulation; and compares the approach with diffusion models in terms of output, interpretability, controllability, cost, failure modes, and use cases. Practical engineering recommendations cover coarse-to-fine stroke budgets, palette limits, stroke logs, evaluation thresholds, textual feedback, and originality governance. The article is intended for readers interested in explainable, reproducible, auditable, and locally editable image-generation workflows.

    1. Background: Two Different “Generation” Paths

    In common industry solutions, text-to-image generation usually relies on diffusion models. The model starts from random noise and gradually produces an image through multiple denoising steps. This approach has the advantages of being end-to-end, fast at image generation, and broad in style coverage. However, the output object is essentially pixels or latent variables. The process is difficult to explain stroke by stroke, and it is also difficult to intervene precisely in the middle of generation.

    This article discusses another path: instead of calling an image-generation model, it lets a large model with code-generation capability write an executable program that simulates real brushes, pigment, and canvas on a virtual canvas. The painting process is decomposed into a large number of independent brushstroke instructions, which the program executes one by one to form the final image. The output is not a “finished image” but a “painting program + stroke sequence.” This makes the creative process closer to human painting: first composition, then blocking in color, then refinement, and finally correction.

    The value of this path is not to replace diffusion models, but to provide a generation method that is explainable, reproducible, auditable, and locally editable. It has unique reference value for applications that need to control stroke semantics, record the creative process, study painting instruction, or build procedural art styles.

    2. Core Idea: Let the Model Output a “Painting Program” Rather Than an “Image”

    The core of programmatic painting can be summarized in three points:

    1. Change in output form: The model generates code that includes canvas initialization, brush definitions, color mixing, path planning, stroke down and stroke up, observation, and correction logic.
    2. Separation of execution and rendering: The model is responsible for planning and generating instructions, while the painting engine applies the instructions to a virtual canvas and simulates brush texture, pigment wetness, and canvas absorption.
    3. Feedback loop: During multiple rounds of painting, the model observes the current canvas, checks whether structure, proportion, light and shadow, and lines are reasonable, and then uses new strokes to cover, glaze, or add local details.

    In a public demonstration, the generation script for a single work was about 1,000 to 2,000 lines, and the final image was accumulated from a large number of brushstrokes; a photo-realistic attempt used about 700,000 simulated strokes. Another constrained experiment allowed only 111 strokes to complete a bird at sunrise. The first stroke color was #30346a, the brush width was 90 pixels, and it included five slightly wavering path points. The model also deliberately set about 7 pixels of sway to simulate the feel of a human arm being unable to draw an absolutely straight line. These data show that stroke count is not the only quality metric; the key lies in stroke semantics, planning hierarchy, and feedback-based correction capability.

    3. System Architecture: A Layered Design from Intent to Brushstrokes

    A practical programmatic painting system can usually be divided into five layers.

    1. Intent understanding and style planning layer

    This layer converts user goals into a painting plan, including subject, composition, viewpoint, lighting, color tone, texture, brush preferences, and stroke budget. For example, “a photo-realistic shopping cart in a parking lot” would be decomposed into background ground, perspective structure, metal mesh, highlights, shadows, rust, and local reflections. Style planning can also maintain a stable “creative setting” so that the model chooses brushes and colors around fictional experiences and preferences, reducing simple imitation of existing styles.

    2. Painting engine layer

    The painting engine provides a virtual canvas, brush model, pigment model, and texture model. The brush model includes at least width, hardness, wetness, pressure, edge roughness, and texture; the pigment model handles color mixing, wet spreading, and drying changes; the canvas model handles paper or fabric texture, absorption rate, and surface relief. The closer the engine is to physical processes, the more the model needs to think in “painting language” rather than directly “pasting pixels.”

    3. Brushstroke instruction layer

    Each stroke can be represented as a structured instruction containing color, width, wetness, path points, pressure curve, and jitter amplitude. Path points are not simple straight lines but smooth curves with slight wavering. Whether a stroke can be undone after it is applied is an important constraint: if it cannot be undone, the model must plan more thoroughly before applying the stroke and correct errors through subsequent covering strokes.

    4. Observation and evaluation layer

    The model needs to read canvas snapshots or local regions and perform self-checks against the goal. Evaluation can be rule-based, for example checking subject contours, light-dark contrast, edge sharpness, and color deviation; it can also be a semantic judgment made by the model. When it finds that “the back is too thin and the lines are messy,” subsequent strokes can widen and cover, reduce contrast, and reorganize edges.

    5. Execution and export layer

    This layer executes code, performs incremental rendering, saves stroke logs, and exports the final image and process video. Stroke logs are critical for reproduction, auditing, and secondary editing.

    4. Brushstrokes and Physical Simulation: Giving Each Stroke “Weight”

    An illustrative pseudocode example is as follows:

    1. Stroke {
    2. color: RGB
    3. width_px: float
    4. wetness: float // 0–1 wetness level
    5. points: [(x, y), ...]
    6. pressure: [p1, p2, ...]
    7. jitter_px: float
    8. }
    9. function render(canvas, strokes):
    10. for stroke in strokes:
    11. brush = make_brush(stroke.width_px, stroke.wetness)
    12. path = smooth_path(stroke.points, stroke.jitter_px)
    13. for point in path:
    14. canvas = deposit_pigment(canvas, brush, point, stroke.color)
    15. canvas = simulate_wet_spread(canvas, point)
    16. return canvas

    This pseudocode reflects several key points: a brush is not a fixed pixel block but a deposition process with wetness and pressure; paths are smoothed and jittered to avoid a mechanical straight-line feel; pigment spreads and mixes on the canvas. In engineering, it is also necessary to handle stroke overlap, color layering order, wet-dry changes, and edge texture. When the number of strokes reaches hundreds of thousands, rendering performance becomes a bottleneck. Common optimization methods include spatial indexing, dirty-rectangle partial refresh, chunked stroke serialization, and deterministic random seeds.

    5. Observation-Correction Loop: Planning Capability Under Non-Undoable Constraints

    The difficulty of programmatic painting is not only “painting something that looks similar,” but “maintaining structural stability over a long sequence.” A typical loop is as follows:

    1. budget = 700000
    2. plan = model.plan(goal)
    3. while canvas.score(goal) < threshold and used_strokes < budget:
    4. strokes = model.next_strokes(plan, canvas.snapshot(), history)
    5. canvas.apply(strokes)
    6. history.append(strokes)
    7. plan = model.reflect(goal, canvas.snapshot(), history)

    In experiments where strokes cannot be undone, the model must output each stroke as a coordinate instruction and cannot roll back after applying it. Corrections can only rely on subsequent glazing, covering, and local additions. This forces the model to develop stronger hierarchical planning: first use large brushes to establish the overall shape and light-dark structure, then use medium brushes to build structure, and finally use small brushes to handle edges and highlights. If an error is found, the response is not “delete and start over” but “cover it with more reasonable strokes.”

    6. Comparison with Diffusion-Based Generation

    • Output object: Diffusion models output pixels/latent variables; programmatic painting outputs code, stroke sequences, and process logs.
    • Interpretability: The latter can be audited stroke by stroke and can answer “why was this stroke placed here?”
    • Controllability: It can limit stroke count, palette, brush physics, stroke order, and non-undoable constraints.
    • Generation cost: Photo-realistic results may require a large number of strokes, and long-sequence planning has a high cost; diffusion models usually have advantages in single-image generation efficiency.
    • Failure modes: Diffusion models may exhibit structural drift; programmatic painting may exhibit planning failure, messy strokes, or locally over-detailed areas.
    • Use cases: The former is suitable for rapid creative exploration; the latter is suitable for explainable creation, painting instruction, procedural textures, and style research.

    7. Engineering Practice Recommendations

    1. Coarse to fine: Allocate the stroke budget across three levels—composition, color blocking, and refinement—to avoid getting stuck in local details from the start.
    2. Limit the palette: Reducing the number of colors can improve style stability and also reduce the complexity of pigment mixing simulation.
    3. Save stroke logs: Record color, width, path, wetness, and random seed to ensure reproducibility.
    4. Set stroke budgets and evaluation thresholds: Prevent unlimited additions and avoid stopping too early.
    5. Introduce textual feedback: Use feedback such as “edges are too hard,” “shadows are too cool,” or “metal reflections are insufficient” to guide the model in adjusting brushes and engine parameters.
    6. Govern originality: Let the model maintain fictional creative settings and form a stable style through feedback, avoiding simple imitation of existing works.

    8. Conclusion

    Painting without calling image models and using code to simulate real brushes essentially turns the generation problem into a combined problem of “program planning + physical simulation + feedback correction.” It sacrifices some end-to-end efficiency in exchange for an explainable process, auditable strokes, adjustable style, and reproducible creation. For scenarios that require deep control over the painting process, this is a technical path worth studying; for scenarios that pursue rapid image generation, diffusion-based solutions remain efficient. The two are not replacements for each other, but complementary approaches for different constraints.