Code-Driven Painting Without Image Models: Simulating Brushstrokes One Stroke at a Time
Instead of generating pixels in one pass, programmatic painting turns image creation into an executable sequence of brushstroke instructions. This article explains the architecture, execution workflow, brush modeling, feedback loop, style controls, engineering challenges, and practical boundaries of a system that plans and renders paintings locally without directly calling an image generation model.
Traditional text-to-image systems typically produce pixel outputs through an opaque process: given a prompt, the model iteratively denoises a representation in latent space until it produces a finished image. This article explores a different approach: treating image generation as the creation of a painting program.
In this design, the model does not directly call an image generation model. Instead, it generates a large number of independent brushstroke instructions, which a local painting engine executes one by one on a virtual canvas. Each stroke can include coordinates, paths, color, width, pressure, wetness, and brush type. The canvas maintains paint thickness, moisture, texture, and historical state.
The final work is therefore not an unexplained pixel image. It is a reproducible, auditable, and editable record of the painting process.
The value of this approach is not that it replaces every image generation model. Rather, it provides a complementary path for tasks that require process explanations, stroke-level editing, artistic-style constraints, or educational demonstrations. At the same time, it introduces engineering challenges involving long-range planning, rendering performance, error correction, and evaluation. The sections below cover the core concept, system architecture, execution workflow, brush modeling, feedback and correction, style control, engineering optimization, and practical limitations.
1. Core Concept: Decomposing an Image into an Executable Stroke Sequence
The core of a traditional diffusion model is pixel-level generation. The core of programmatic painting is action-level planning.
The model must first understand the target image, then decompose it into composition, color blocks, lighting, edges, and details. Finally, it translates those elements into brushstroke instructions. The painting engine does not need to understand the target semantics. Its job is to execute instructions and update the canvas state. A structured instruction format decouples the two components.
This separation provides three direct benefits:
- Explainability: Every stroke has explicit parameters, making it easier to identify which stroke caused a problem.
- Reproducibility: Given the initial canvas, stroke sequence, and random seed, the result can be replayed consistently.
- Correctability: When an error is found, the system can add corrective strokes, cover an area, or adjust subsequent strokes instead of regenerating the entire image.
The trade-off is that the model needs strong long-range planning capabilities. Otherwise, the result may contain highly detailed local regions while the overall composition remains unbalanced.
2. System Architecture: Coordination Between Planner, Engine, and Observer
A complete programmatic painting system usually contains three layers.
2.1 Artistic Planning Layer
This layer interprets the task requirements and determines the canvas size, composition, color palette, brush strategy, and style constraints. It may first produce a coarse plan such as:
- Lay down large background color blocks.
- Establish the main subject and its outline.
- Add highlights and surface texture at the end.
2.2 Stroke Planning Layer
This layer converts the coarse plan into an executable sequence of strokes. Each stroke must specify fields such as color, width, path points, pressure curve, wetness, and brush texture.
The number of strokes may range from a few hundred to hundreds of thousands, depending on the target level of detail and the capabilities of the rendering engine.
2.3 Painting Engine and Observer
The engine applies strokes and updates the canvas buffer. The observer periodically reads canvas snapshots and compares them with the target description or a planning sketch. When it detects a deviation, it triggers additional stroke planning.
The observer does not have to be a complete image model. It can combine rule-based evaluation, local statistics, perceptual metrics, and human feedback.
A simplified example looks like this:
canvas = initialize(width, height, texture_parameters)plan = language_model.generate_painting_plan(target_description,artist_profile,canvas_constraints)for stroke in plan.stroke_sequence:canvas.apply(stroke) # Once applied, the stroke cannot be undonesnapshot = canvas.observe()deviation = evaluator.compare(snapshot, target_description)if deviation.requires_correction:plan.append(correction_planner.generate_strokes(deviation))
A stroke can be represented as:
stroke = {color: "#30346a",width: 90,path_points: [...],pressure_curve: ...,wetness: ...,brush_type: ...}
3. Execution Workflow: Coarse to Fine, With Coverage but No Undo
Programmatic painting usually follows a coarse-to-fine workflow.
The first stage lays down large color blocks and the background, establishing the overall palette and lighting relationships. The second stage defines the main subject, outline, and structural elements. The third stage adds local details, edge transitions, and highlights. The fourth stage observes the result and applies corrective strokes to cover errors.
The key constraint is that a stroke cannot be undone after it is committed. This mirrors physical painting and forces the model to plan more carefully. Correction does not mean rolling back history. Instead, new strokes cover, blend, or reduce the visual impact of earlier strokes.
From an engineering perspective, historical snapshots can still be preserved for auditing. However, the execution semantics should remain append-only so that the model cannot rely on unlimited undo operations and neglect planning quality.
Public experiments illustrate two typical scales. One used approximately 700,000 simulated strokes to create a parking-lot shopping-cart scene, with a program reaching roughly a thousand lines of code. Another created a sunrise-and-birds image with 111 strokes. Each stroke included a color value, a width of 90 pixels, and multiple path points, with slight movements of around 7 pixels used to imitate the fact that a human hand cannot draw a perfectly straight line.
These examples show that stroke count is not the only objective. The important factor is matching stroke granularity to task complexity.
4. Brush Physics: Texture, Wetness, and Canvas Surface
To make programmatic painting resemble real brushwork, the engine needs to model several physical properties.
- Color determines pigment hue and opacity.
- Width and pressure curves control stroke thickness and edge softness.
- Path points define the movement trajectory.
- Wetness affects pigment diffusion, blending, and drying speed.
- Brush texture determines internal irregularities within a stroke.
- Canvas texture affects pigment adhesion and reflections.
The goal does not need to be complete physical simulation. It should instead be perceptually plausible.
For example, slight path jitter can create a hand-painted appearance. A wetness parameter can allow neighboring strokes to blend within limits. Surface irregularities can produce fine texture in highlighted areas.
When generating instructions, the model must select brush types and parameters according to the target material. A single brush treatment should not be applied uniformly to every region.
5. Observation and Correction: Letting the Model Inspect Its Canvas
Programmatic painting should not be a process of blind execution after a single planning step. During a long drawing sequence, the model needs to inspect canvas snapshots periodically and check composition, proportions, lighting, edge quality, and local errors.
For example, if the subject’s back is too narrow or the lines appear cluttered, later strokes can widen the area, reduce contrast, or add transitional colors.
Correction strategies generally fall into three categories:
- Local additions: Add missing details.
- Overpainting: Correct obvious errors by covering the affected area.
- Blending strokes: Soften harsh or unnatural edges.
The observer can combine rules and perceptual metrics, including regional color distributions, edge density, structural similarity, and human feedback.
For high-precision tasks, the system should observe more frequently. During the large color-block stage, observation frequency can be reduced to save computation.
6. Style Control: Constraining Stroke Strategies with an Artist Profile
Programmatic painting can fall into two extremes: mechanically repetitive strokes or excessive imitation of an existing style.
A more robust approach is to maintain a fictional artist profile that defines preferred brushes, color tendencies, compositional habits, detail density, and correction methods. This profile is not a fixed template. It is a set of adjustable constraints.
Text-based feedback can guide the model in adjusting brush parameters and engine behavior, for example:
- Reduce the density of highlight strokes.
- Make the background strokes looser.
- Keep the subject’s edges cleaner.
The goal is stylistic consistency, not copying a specific artist. Style should emerge from the combination of stroke strategies, color relationships, and observation-and-correction rules rather than from reproducing existing works.
7. Engineering Challenges and Optimization Directions
The main engineering challenges of programmatic painting involve four areas.
7.1 Long-Sequence Planning
Sequences containing tens or hundreds of thousands of strokes should be planned by layer, region, and increment. Generating the entire instruction set at once can create excessive memory and planning demands.
7.2 Rendering Performance
Applying strokes, blending colors, and sampling textures require batching, spatial indexing, and incremental snapshots. Parallel rendering may be necessary for large workloads.
7.3 State Management
Canvas moisture, paint thickness, and historical snapshots can consume significant memory. Compression and layered storage are therefore important.
7.4 Evaluation
Evaluation should cover more than perceptual quality. It should also measure stroke plausibility, process reproducibility, and results from human blind reviews.
8. Suitable Use Cases and Boundaries
This approach is well suited to scenarios that require:
- Explainable painting processes
- Stroke-level editing
- Art education and demonstrations
- Explicit style constraints
- Reproducible painting logs
It is less suitable for tasks that simply require high-throughput pixel generation. Traditional image generation models still have advantages when complex semantic understanding and photorealistic detail are the main priorities.
A more practical positioning is complementary:
- Use an image model for rapid visual ideation.
- Use programmatic painting for process-based expression and fine-grained control.
Recommended practices include:
- Plan from coarse structure to fine detail.
- Preserve append-only execution semantics.
- Design stable fields for stroke instructions.
- Observe snapshots regularly and limit the scope of corrections.
- Record the random seed and engine version.
- Build evaluation sets that combine automated metrics with human review.
- Represent style constraints as adjustable parameters rather than fixed templates.
Conclusion
Painting without directly calling an image model and simulating a brush stroke by stroke with code fundamentally transforms image generation into a planning-and-execution problem.
It turns the painting process from a black-box output into program behavior that can be inspected, reproduced, and corrected. This makes programmatic painting a promising engineering path for controllable and process-aware generative art, while also leaving room for traditional image generation models in tasks where speed, semantic complexity, or photorealistic detail are more important.
