Simulated Brushstroke Rendering Without Image Models: A Technical Breakdown

    This article explores a code-driven alternative to diffusion-based image generation, where an LLM writes an executable drawing program and a physics-based engine renders brushstrokes one by one on a virtual canvas. It breaks the approach into four layers (semantic planning, stroke instructions, physical simulation, and feedback correction), details the physical modeling of bristle pressure, paint wetness and canvas texture, explains the engineering value of irreversible stroke constraints, and compares style externalization and iteration feedback against prompt-and-seed control. A side-by-side comparison with diffusion pipelines, deployment guidance around compute tiering and observability, and a frank discussion of throughput and feedback-fidelity limitations are included for developers evaluating controllable, replayable generative workflows.

    1. The Starting Point: Why Take a Path Outside “Pixel Generation”

    Most mainstream image generation today is built on diffusion models: starting from random noise, the model iteratively denoises in latent space and finally outputs a finished image made of a pixel matrix in a single pass. This path is attractive because it is end-to-end, fast, and visually high quality. But it has one structural characteristic: the process is a black box, and the result is an irreversible set of pixels. Users receive an image, not an explanation of how that image was drawn.

    The approach shown in the original case study runs in the opposite direction. No image generation model is called at all. Instead, an intelligent coding model writes an executable drawing program that simulates the movement of a real brush on a virtual canvas and lets the picture “grow” stroke by stroke. The output has two layers: the final canvas, and the code that produced it. The latter is the real technical asset here.

    That difference has a direct consequence: painting shifts from “one inference call” to “one program execution.” The model owns planning and decision-making; the rendering engine owns physics simulation. The two are decoupled. Understanding this is a prerequisite for understanding every engineering detail that follows.

    2. Architecture Breakdown: Four Layers

    Abstracted out, this kind of system splits into four layers that communicate through explicit data contracts.

    1. Semantic planning layer: the model interprets the creative intent (for example, “a shopping cart in a parking lot” or “a bird at sunrise”) and decomposes it into scene elements, composition proportions, light direction, and drawing order.
    2. Brushstroke instruction layer: the model emits structured stroke instructions rather than an image. Each instruction carries at least color, brush width, a sequence of path points, jitter amplitude, and paint wetness.
    3. Physical simulation layer: the rendering engine interprets the instructions and simulates bristle deformation, paint transfer, wet diffusion, and canvas texture engagement, rasterizing instructions into pixel changes.
    4. Feedback correction layer: the model observes the current canvas state (typically fed back as a downsampled visual description or statistical features), judges the deviation, and appends new strokes to cover, deepen, or soften.

    A schematic instruction structure looks like this. The key point is that every stroke is an independent, auditable piece of data:

    1. @dataclass
    2. class BrushStroke:
    3. color: str # Hex color code, e.g. "#30346a"
    4. width: int # Brush width in pixels
    5. wetness: float # Paint wetness, affects edge diffusion
    6. points: list[tuple[float, float]] # Path control points
    7. jitter: float # Deliberately introduced jitter
    8. blend: str # Blend mode: cover / deepen / soften

    In more restrained experiments, a whole piece may consist of only about a hundred strokes. In scenes aiming for photographic realism, the stroke count balloons into the hundreds of thousands. The architecture is identical; only the planning granularity and compute budget differ.

    3. Key Mechanism One: Physically Grounded Brushstroke Modeling

    “Simulating a real brush” is not a figure of speech. For the output to carry a hand-painted feel, the simulation layer has to handle at least three categories of physical quantity.

    Bristles and pressure sensitivity. A real brush touching down is not a rectangular stamp. Bristles deform under pressure, so a line ends up dense in the middle and lighter toward both edges. In engineering practice this is approximated with a width function that varies along the path plus an alpha falloff curve.

    Paint wetness and diffusion. Wet paint bleeds between canvas fibers and produces soft edges; dry paint yields sharp edges and strong coverage. Making wetness a tunable parameter lets the model produce watercolor-like transitions or oil-paint impasto within the same engine.

    Canvas texture engagement. A canvas is not an ideal plane. Its surface relief makes paint cling more at the raised points. Introducing low-frequency noise as a texture height field gives strokes a natural grain and avoids a “plastic” look.

    One detail is worth calling out: deliberate imperfection. In the original case, the model designed roughly 7 pixels of sway into the very first stroke and explained that a human arm cannot draw a perfectly straight line. This is not a defect but anthropomorphic modeling: injecting controlled jitter during path point generation noticeably reduces the mechanical feel of computer graphics.

    4. Key Mechanism Two: Irreversibility Constraints and One-Shot Planning

    Another set of experiments imposed harsher rules: once a stroke lands on the canvas it cannot be undone, and the model has to emit each stroke individually as a coordinate instruction.

    The engineering value of this constraint far outweighs its “game-like” quality:

    • It forces forward planning. The model has to think through composition and light-and-dark relationships before touching down, rather than relying on trial, error, and rollback. This is closer to the cognitive process of real painting.
    • State becomes replayable. Because every stroke is an ordered instruction, the canvas state is a deterministic function and any intermediate frame can be reproduced, which helps with debugging and teaching demos.
    • Cost becomes measurable. Total stroke count, average path length, and color usage frequency are all directly countable metrics, giving compute budgeting and quality assessment a quantitative handle.

    The tradeoff is an extremely low error tolerance. A common engineering compromise is to introduce “overwritable but not deletable” semantics: the model may append translucent strokes to correct deviations, but may not roll back to a historical state. This preserves the authenticity of irreversibility while still leaving room for the model to recover.

    5. Key Mechanism Three: Style Personas and Iterative Feedback

    Beyond realism, the more interesting output of this kind of system is style. When the model is allowed to define an “artist persona” with a fictional background and stable preferences, and to tune brush and engine parameters based on textual feedback, the output develops a recognizable consistency: a preference for cool palettes, a habit of long strokes, a tendency toward negative space.

    This points to a workable engineering pattern: externalize style as configuration rather than baking it into weights. A style configuration can hold palette constraints, a brush set, jitter ranges, and a maximum stroke density, and can keep evolving alongside the feedback loop. Compared with fine-tuning model weights, this approach is cheaper to iterate, more explainable, and easier to version-control and A/B test.

    The feedback loop usually compresses the canvas state into a textual description the model can consume (dominant color distribution, contrast, composition center of gravity offset, and so on) and then asks the model for the next batch of instructions. The bottleneck here is not generation but the fidelity of the “visual understanding” being fed back.

    6. Engineering Comparison with Traditional Diffusion Pipelines

    Dimension Code-simulated brushstrokes Diffusion pixel generation
    Deliverable Image + executable drawing program Image only
    Process explainability High, auditable stroke by stroke Low
    Local controllability Strong, can append strokes at a specific point Depends on inpainting and masks
    Per-run cost High, scales linearly with stroke count Relatively controllable
    Style consistency Stabilized via configuration and feedback Depends on prompts and seeds
    Best-fit scenarios Teaching demos, controllable creation, process replay High-throughput batch generation

    The conclusion is not an either/or. A more pragmatic architecture is hybrid: use pixel generation for drafts and composition exploration, then use code-simulated brushstrokes for controllable refinement in key regions, while keeping a complete stroke log for auditing.

    7. Implementation Guidance and Cloud Deployment

    To deliver something similar in production, a few points are worth attention:

    • Tier the compute. Planning and feedback are inference-intensive, while simulation and rendering are compute-intensive. They should be deployed separately so they do not contend for the same resources. A container platform handles elastic scaling, and a task queue smooths out bursts in stroke workload.
    • Separate state from artifacts. The drawing program, stroke logs, and intermediate canvases should be written to object storage with versions retained, so runs can be reproduced and traced. Rendering intermediates can live in temporary storage to keep costs down.
    • Make it observable. Monitor and alert on stroke throughput, per-stroke render latency, feedback rounds, and retry counts to locate performance inflection points.
    • Add cost guardrails. Cap stroke counts and feedback rounds so the model cannot fall into endless correction, and make very long runs asynchronous with incremental commits.
    • Cover content safety. The generation pipeline should hook into a unified content moderation capability that validates both input intent and output imagery.

    In scenarios like this one, Baidu AI Cloud typically carries the general capabilities above: a container platform for simulation and inference workloads, object storage for the drawing program and versioned artifacts, a message queue to schedule stroke tasks, and logging plus monitoring and alerting to keep the pipeline observable. Refer to the official documentation for specific product forms and specifications; this article does not touch on any proprietary interface details.

    8. Limitations and Outlook

    The most obvious weakness today is throughput. Hundreds of thousands of strokes mean hundreds of thousands of instruction generations and renders, so latency and cost are far higher than a single pixel generation. Second is feedback fidelity: if the model’s understanding of what the canvas currently looks like is distorted, its corrections will drift. Third is the capability boundary of the engine: how well the model can draw is capped by the physical realism of the simulation engine, not by the model’s own aesthetics.

    Even so, it points to an important direction: the value of generative creation lies not only in the finished piece but in the programmability of the process. When painting is expressed as a series of versionable, replayable, auditable instructions, creation stops being a one-off result and becomes an engineering asset that can keep evolving. For developers, that may be a more worthwhile capability to invest in than “producing one good-looking image.”