Code-Driven Brush Painting Without Image Generation Models
This article describes a way to create images without direct pixel output from an image generation model. A language model plans the painting and writes code or structured stroke instructions, and a painting engine builds the image stroke by stroke on a virtual canvas. It covers a four-layer system architecture, simulation of real brush behavior, a constrained stroke format, error correction when paint cannot be undone, and performance considerations.
1. From Producing an Image to Executing a Painting Process
Having an intelligent system paint does not necessarily mean having an image generation model output pixels directly. Another viable path is this: a language model first interprets the painting request, then writes a program or produces structured instructions. A painting engine executes them to build the image stroke by stroke on a virtual canvas.
The core of this approach is not replacing one generative model with another. It changes how the task is expressed. Traditional image generation systems typically learn an image distribution and generate a picture from conditions such as text. Code-driven painting instead breaks the target into composition, contours, color blocks, texture, and detail, and then carries these out as a sequence of drawing actions.
For example, “a bird standing in the morning light” must be converted into several concrete questions: how to divide the background into regions, which direction the light comes from, how to determine the proportions of the bird’s body and head, where the shadows on the feathers should fall, which details can be suggested with broad strokes, and which must be added with a fine brush.
The final picture is not output directly by the language model. It is produced when the program runs. The language model handles planning and code generation, the painting engine performs the execution, and the canvas records the result.
Not calling an image generation model does not mean the system uses no image capabilities at all. To observe the canvas during painting and detect proportion errors, the system still needs a model with image understanding, or a dedicated geometry detection or image analysis program. Image understanding and image generation are different stages and should not be conflated.
2. System Architecture: Splitting Creation into Four Manageable Layers
A system that is easy to develop, debug, and extend can be divided into four layers.
1. Task and Composition Planning
This layer converts a natural language request into painting constraints, including the subject, background, viewpoint, lighting, color relationships, and style goals.
The planning output should not be a single vague description. It should also contain executable spatial information, such as which area of the canvas the subject occupies, where the horizon sits, and how foreground and background overlap.
For complex objects, the main contours and perspective structure should be determined before materials are handled. Take a shopping cart in a parking lot as an example. The geometric relationships between the frame, basket, and wheels matter more than small metallic highlights on the surface. If the basic perspective is wrong, adding many highlights and textures still leaves the picture unconvincing.
2. Stroke Planning
This layer turns painting elements into concrete strokes.
A stroke should at least specify its path, color, width, opacity, and execution order. To approximate a real brush more closely, the system can also vary pressure, speed, brush orientation, and paint load along the path.
Developers do not need the language model to generate every tiny stroke. A more practical approach is to have the model generate high-level painting rules, then let the program expand the details. For example, the model describes the direction, density, and color range of feathers, and the program generates the local texture according to those rules.
Therefore, executing a large number of strokes does not mean the model planned the same number of independent actions. When evaluating the system, distinguish the number of high-level decisions, the number of strokes after program expansion, and the actual rendering workload.
3. Brush and Canvas Execution
The execution layer converts stroke instructions into changes on the canvas. It can start with simple two-dimensional color overlay, then gradually introduce brush textures, paint mixing, and canvas roughness.
The key requirement is predictable behavior. The same stroke sequence, initial state, and random seed should produce the same result whenever possible. Otherwise, errors are hard to reproduce and results are hard to compare.
4. Observation and Feedback
At appropriate stages, the system outputs canvas snapshots and checks the gap between the current result and the target.
Feedback should be specific enough to fix. For example: “the outline of the bird’s back is too narrow,” “the wheel centers do not share the same perspective,” or “the background brightness overpowers the subject.” Vague requests such as “make it look more realistic” are not enough.
These four layers form a closed loop:
Requirement understanding → Composition planning → Stroke generation → Canvas execution → Result observation → Local adjustment.
3. Simulating Real Brushes Goes Beyond Adding Random Jitter to Lines
If the system only draws a noisy line along a path, the result is usually a procedural brush effect, not a full physical painting simulation. When developing, state the simulation level clearly so that a visual approximation is not described as strict material physics.
1. Path and Contact Shape
The contact area of a real brush changes with pressure, angle, and direction of motion. A simplified implementation can approximate these effects by varying the brush width, flatness, and orientation.
Under higher pressure, the brush may cover a wider area. As pressure drops, the stroke can gradually taper. The sampling interval along the path also affects the result. Intervals that are too large cause breaks in the stroke. Intervals that are too small increase computation and may cause repeated color accumulation.
Moderate disturbance breaks up mechanical regularity, but it should not be applied uniformly. Sky color blocks, building edges, and feather details need different degrees of path stability. If every line wobbles by the same amount, the result shows obvious algorithmic traces.
2. Paint Load and Wet-Dry Changes
The paint carried by a brush can be modeled as a limited resource. As the brush moves, paint is consumed and color coverage decreases, creating a broken, dry-brush texture.
To represent wet painting, the canvas must also store the moisture level and model how it decreases over time. A new stroke landing on a wet area can spread or mix. A stroke landing on a drier area behaves more like simple coverage.
This can use empirical rules or more complex numerical models. Both have engineering value, but their limits must be stated. Simple color interpolation is not the same as real paint mixing, and the averaging operations common in color representations cannot accurately reproduce the optical behavior of all pigments.
3. Canvas Texture
The unevenness of the canvas affects where paint is deposited. A simplified method generates a fixed texture field and uses it to modulate local coverage or brush contact strength.
The texture is best bound to canvas coordinates rather than randomly regenerated for every stroke. This way, multiple strokes interact with the same surface structure and produce a more consistent sense of material.
The texture should also not be too strong. If the canvas grain is equally visible everywhere, it weakens the main structure and makes the picture look as if a uniform filter has been applied.
4. Replacing Arbitrary Execution Code with Structured Stroke Descriptions
Letting a model generate an entire painting program directly offers high flexibility, but it also increases runtime risk and maintenance cost. A more engineering-friendly approach is to have the model output constrained stroke descriptions, which a trusted executor then interprets and runs.
The following is an illustrative structure. Its fields show the design idea only and do not represent the interface of any existing service:
stroke:path: [(0.12, 0.68), (0.28, 0.64), (0.41, 0.66)]color: (48, 52, 106)width_ratio: 0.035opacity: 0.7pressure: [0.4, 0.8, 0.3]brush_class: flat
Path coordinates and brush width use relative scales, which reduces geometric deviation caused by changes in output resolution. Color, opacity, and pressure require range validation.
The executor should reject out-of-range data, non-finite values, overly long paths, and stroke sequences that exceed the budget. The budget can include the number of samples per stroke, total stroke count, memory usage, and execution time.
If executing general-purpose code generated by a model is truly necessary, it should run in an isolated environment with restricted file access, network access,
