Simulating Brush Strokes With Code: A Technical Guide Without Image Models

    This article explores an alternative to diffusion-based image generation: writing a program that simulates physical brush strokes on a virtual canvas instead of calling an image model. It explains the core mechanism of breaking a painting into independent stroke instructions, the three-layer rendering engine that models brush geometry, paint medium, and canvas texture, and the multi-round self-correction loop that lets a model observe and revise its work. It also covers style shaping through a fictional artist persona, practical engineering recommendations, and the broader value of turning generation into a transparent, auditable, and reproducible program.

    1. Why Painting With Code Deserves Serious Attention

    In the popular imagination, AI image generation means typing a prompt and waiting for a model to output a finished image. Most mainstream solutions are built on diffusion models, which start from random noise and progressively approach the target image through multiple denoising steps. This approach is end-to-end, fast, and visually strong, but it carries an implicit assumption: every pixel is decided by the model in one pass, and humans cannot intervene in the intermediate process.

    This article discusses a different technical route: without calling any image generation model, a coding model writes a drawing program that simulates the motion of a real brush on a virtual canvas, completing the work stroke by stroke. The “work” here is essentially executable code. The code drives a self-built drawing engine responsible for brush deformation, paint wetness, canvas texture, and color mixing. The final output is not the result of a single forward pass of model weights, but a program that is reproducible, auditable, and parameterizable.

    There are three reasons this route deserves developers’ attention:

    • Controllable process: every stroke is an explicit instruction; coordinates, brush width, color values, and jitter amplitude can all be recorded, replayed, and modified.
    • Strong explainability: when something goes wrong, you can pinpoint the specific stroke instead of facing a black-box image with no way to diagnose it.
    • Composable engineering: the drawing engine, stroke planner, and visual feedback module can be split into independent components, making them easy to test and iterate.

    2. Core Mechanism: Decomposing a Painting Into Independent Stroke Instructions

    Traditional image generation is result-oriented; code-simulated painting is process-oriented. The key abstraction of the latter is to break a painting into a large number of independent stroke instructions, let the model plan the order and parameters itself, and hand them to the rendering engine for execution one by one.

    A stroke instruction typically contains the following elements:

    • start and end coordinates plus path control points;
    • brush type (round, flat, fan, dry brush, and so on);
    • brush width and pressure curve;
    • color value and paint wetness (which determine edge diffusion and color blending);
    • jitter amplitude (simulating the fact that a human arm cannot draw a perfectly straight line).

    A schematic instruction structure is shown below (it only expresses how data is organized, not a specific product interface):

    1. stroke = {
    2. "brush": "flat", # brush type
    3. "color": "#30346a", # color value
    4. "width": 90, # brush width (pixels)
    5. "wetness": 0.6, # paint wetness
    6. "points": [(x0, y0), (x1, y1), (x2, y2), (x3, y3)],
    7. "jitter": 7 # path point jitter amplitude (pixels)
    8. }
    9. engine.render(stroke)

    In a public technical sharing case, an engineer asked the model to draw a bird at sunrise, restricted to simulating brush physics, wet paint, and canvas texture through code only. A roughly 21-second video recorded the whole process from a blank canvas to the finished piece, using 111 strokes in total. The first stroke used a dark blue color and a 90-pixel brush width, with a path containing 5 slightly wobbling control points and a jitter amplitude of about 7 pixels. The model explained that this wobble was deliberate, because a human arm cannot draw a perfectly straight line either.

    Another case asked the model to create a work “as close to photorealism as possible.” The model ultimately chose to draw a shopping cart in a parking lot, using about 700,000 simulated strokes in total. Comparing the two shows that stroke count is not a quality metric; it is determined jointly by the complexity of the scene and the chosen strategy. The 111-stroke minimalist piece and the 700,000-stroke realistic piece are two convergence paths of the same “instruction-based painting” paradigm under different constraints.

    3. The Rendering Engine: Three Layers of Brush, Paint, and Canvas Simulation

    To make code-drawn images look like paintings, the rendering engine must simulate at least three layers of physical intuition.

    The first layer is brush geometry. A brush is not a simple dot but a shaped contact surface. A flat brush leaves hard edges at turns, and a fan brush naturally splits when lifting off. The engine must compute the coverage area at each sampling point according to the brush type and interpolate deformation along the path.

    The second layer is the paint medium. Wet paint diffuses slightly among canvas fibers, forming soft edges, while dry paint shows graininess and broken white. The wetness parameter directly affects how colors mix when layered: wet-on-wet produces gradient transitions, while dry-on-wet leaves clear boundaries.

    The third layer is canvas texture. A canvas is not an ideal plane; fiber undulations cause uneven paint deposition. The engine usually approximates texture height with a noise field, then modulates the amount of paint at the brush contact point according to the undulations, so that fine bristle marks and grain become visible when zoomed in.

    Only when these three layers combine does a “stroke” gain the ability to be repeatedly covered, corrected, and marked, which also provides the physical basis for the “multi-round self-check” discussed later.

    4. Multi-Round Self-Check: Letting the Model Observe the Canvas and Fix Errors

    The biggest difference between code painting and one-shot generation is that the drawing process can be interrupted, observed, and corrected. A typical flow is a closed loop:

    1. The model outputs a batch of stroke instructions;
    2. the engine renders them onto the virtual canvas;
    3. the model “observes” the current canvas (usually by feeding back a comprehensible description or downsampled information about the canvas state);
    4. after finding deviations, it adds new strokes to cover, thicken, or fill in color;
    5. repeat until a stopping condition is met.

    One detail from a public case is illustrative: when the bird’s back was drawn too thin and the lines looked messy, the model covered the original area with thicker strokes, making the residual bristle marks at the edges look more like fluffy feathers. The key here is not “erase and redraw” but additive correction that leverages the coverability of the medium, consistent with the real-painting experience of “paint over a mistake with another layer.”

    One constraint deserves special engineering attention: irreversibility. If strokes cannot be undone once laid down, the model must be forward-looking: plan the large color blocks and light-dark relationships first, then progressively converge on details. This effectively turns painting into a constrained sequential decision problem, demanding far more planning ability than single-step generation.

    5. Style Shaping: From Imitation to a Self-Consistent Artistic Persona

    In early similar experiments, model works were criticized for sticking too closely to existing artistic styles. The improvement was not to intensify imitation, but to have the model first construct a fictional artist character: define that character’s background, preferences, habitual colors, and brush habits, then have the model constrain its painting decisions as that character. After finishing the work, textual feedback points out problems (for example, “the edges are too hard” or “the dark areas lack depth”), guiding the model to adjust brush parameters and engine behavior rather than editing the image directly.

    The engineering value of this approach is that style is externalized into a set of adjustable parameters and constraints, instead of being a hidden tendency inside weights. Style therefore becomes describable, reproducible, and version-manageable.

    6. Engineering Implementation Recommendations

    To build similar capabilities in your own project, proceed in the following order:

    • Engine first, intelligence later: prioritize implementing the three layers of brush, wetness, and texture simulation, and ensure rendering results are reproducible.
    • Define the instruction protocol first: establish a stable stroke data structure so the planner and the engine are decoupled.
    • Add an observation channel: provide the model with a readable feedback of the canvas to form a “draw-observe-correct” loop.
    • Make constraints explicit: irreversibility of strokes, a cap on total stroke count, and the color palette range should all be fed in as hard constraints.
    • Parameterize style: break the artistic persona into configurable items for comparison experiments and regression testing.
    • Leverage general cloud capabilities: rendering tasks can run on a container platform with elastic scaling, stroke instructions and versions can be archived in object storage, long-running tasks can be decoupled with message queues, and runtime metrics can be connected to logging services and monitoring alerts, making it easier to locate rendering anomalies and performance bottlenecks.

    7. Conclusion

    “Simulating brush strokes with code without calling an image model” is not meant to replace diffusion models, but to offer a complementary path that is transparent in process, interventable, and auditable. It turns painting from “one-shot generation” into “a runnable program,” making strokes first-class citizens. For developers, the real takeaway is not replicating a famous painting, but mastering a methodology for decomposing complex generation tasks into controllable steps. This methodology applies equally to texture generation, chart drawing, industrial path planning, and other scenarios that require an explainable process.