AI Code-by-Code Drawing: A Technical Breakdown of LLM-Driven Brushstroke Rendering
This article examines an alternative approach to AI visual creation in which a large model writes Python code to simulate brush movements on a virtual canvas instead of calling an image generation model. It compares diffusion-based generation with programmatic brushstroke rendering across speed, interpretability, local correction, resource bottlenecks, and use cases, then breaks down the core techniques including brush parameters, path jitter, the observe-and-correct loop, stroke count, and a minimum viable implementation. It also covers multi-agent coordination, an engineering adoption checklist, cloud platform capability mapping, common errors and troubleshooting, limitations, and an FAQ.
Introduction: From Generating Results to Executing a Process
A recent demonstration from a large model showed a different way to draw: instead of calling an image generation model, it writes Python programs that simulate brush movements on a virtual canvas and completes the work stroke by stroke. This raises a fundamental question: must AI visual creation always follow the “from noise to image” path? This article breaks down how it works, how it differs from mainstream approaches, and what it takes to implement and troubleshoot.
1. Diffusion Generation vs. Programmatic Brushstrokes: How to Choose
Diffusion models start from random noise and denoise step by step under text conditioning until they converge on the target image. The process is end-to-end and fast, but the intermediate results have no semantic explanation, and local fixes require regeneration. Programmatic brushstroke drawing breaks painting into four layers: a canvas model, a brush engine, path planning, and execution with feedback. Every stroke is a function call, so the process is auditable and interruptible.
| Dimension | Diffusion Generation | Programmatic Brushstroke Drawing |
|---|---|---|
| Generation speed | Seconds (common resolutions, batch output) | Hundreds of strokes take minutes; hundreds of thousands of strokes can take hours, depending on model size, canvas resolution, stroke count, and whether preview observation is enabled |
| Process interpretability | Low, black-box iteration | High, every step is auditable |
| Local correction | Weak, requires regeneration | Strong, add new strokes on top |
| Resource bottleneck | GPU compute | Mainly multi-turn LLM inference calls; the bottleneck shifts from compute to call count and latency |
| Use cases | Fast image output, style transfer | Fine-grained controllable creation, teaching demos, physical simulation |
The caveat: programmatic brushstrokes have clear advantages when controllability, auditability, and iterability come first, provided intermediate states are readable and iterative correction is allowed. If the only requirement is fast image output, the diffusion route is more suitable.
2. Core Techniques of Stroke-by-Stroke Drawing
1. Brush Parameters and the Rendering Contract
brush_params = {"type": "round", # round/flat/fan, defaults to round"width": 90, # unit: pixels, range 1-512"color": "#30346a", # RGB hex, converted to CMYK internally by the renderer"opacity": 0.85, # 0.0-1.0, defaults to 1.0"wetness": 0.6, # 0.0-1.0, affects spread radius"texture": "bristle", # bristle texture mode"pressure_curve": [0.3, 0.6, 1.0, 0.8, 0.4]}
This dictionary is the input contract for the rendering engine: default values make fields optional, units are unified in pixels and normalized floats, which makes validation straightforward.
2. Path Jitter
import randomdef add_jitter(path_points, jitter_radius=7):return [(x + random.uniform(-jitter_radius, jitter_radius),y + random.uniform(-jitter_radius, jitter_radius))for x, y in path_points]
The jitter amplitude must scale with canvas resolution. At high resolutions it should be scaled up proportionally, otherwise the jitter becomes invisible.
3. The Observe-and-Correct Loop
The flow is: output a batch of strokes → the engine executes them and updates the canvas → the model reads the canvas or a low-resolution preview → evaluates the deviation from the target → outputs corrective strokes for the deviating regions. This loop is structurally identical to the sense-decide-act loop in robot control.
4. Constraint Setup and Stroke Count
Under a strict setup where each stroke is output individually, marks cannot be undone, and only code is used to simulate physical properties, one public video sample used about 111 stroke calls and another dusk-scene sample used 280 strokes, both in the hundreds range. Larger canvases and finer strokes can scale this to the hundreds of thousands.
5. Minimum Viable Implementation (MVP) Steps
Fix the canvas resolution → build in three brush types (round, flat, fan) → fix the prompt → cap the maximum strokes per task → store each stroke instruction as JSON → support resuming from a checkpoint. Fix resolution and brush types first, then open up wetness and pressure_curve later.
3. Multi-Agent Coordination Architecture
In internal tests disclosed in a model vendor’s 2025 public materials, this capability was used to explore open problems in black hole physics, to work with a circuit board manufacturer to design three functional electronic devices, and to coordinate more than 1,000 sub-agents writing an operating system that runs on a laptop within 8 days. These are all vendor-published test setups, not guarantees of general capability.
Main agent (decomposition and scheduling)├─ Sub-agent A (planning) → execute → verify → feedback├─ Sub-agent B (implementation) → execute → verify → feedback├─ Sub-agent C (testing) → execute → verify → feedback└─ Result aggregation and global validation
Design points: break the task into independently verifiable subtasks; verify as soon as each step is done; send failures back to trigger replanning; when running in parallel, allocate resources and avoid conflicts.
4. Engineering Adoption Checklist
1. AI Coding Tools
Break refactoring into small steps and run tests immediately after each step; mark a “verified state” with a commit hash or snapshot, roll back to the last correct snapshot on failure, and isolate the impact of failures on a separate branch to avoid polluting the main branch.
2. An Executable Visual QC Process
Input: product images or an image stream; steps: zoned scanning → defect candidate output → threshold decision → human review feedback loop; requirements: clear definitions of false positive and missed detection rates, plus sample size requirements (for example, no fewer than several hundred labeled samples per defect class).
3. Robot Simulation
Brush physics modeling corresponds to end-effector modeling, path planning corresponds to joint sequences, and canvas observation corresponds to sensor feedback — the same closed-loop architecture.
5. Cloud Platform Capability Mapping
| Capability | Corresponding Architecture Layer |
|---|---|
| Container platform | Scheduling layer: elastic scaling of rendering and inference |
| Object storage | Snapshot layer: persistence of canvas state and instruction sequences |
| Message queue | Distribution layer: asynchronous decoupling of multi-agent tasks |
| Logging and monitoring | Tracing layer: per-stroke parameters, timing, exceptions |
| Model service | Inference layer: long context and multi-turn planning |
6. Common Errors and Troubleshooting
Brush parameter overfitting makes the image muddy: lower opacity and wetness. Low-resolution previews cause misjudgment: recheck key regions at full resolution. Errors accumulate with no undo: lay down large color blocks first, then add details. Stroke order causes occlusion: sort from far to near.
Limitations remain: speed is constrained by call count, the quality ceiling depends on the model’s planning ability, and abstract semantic expression needs improvement. In the future it could be combined with diffusion models for sketching plus refinement, or used for real-time interactive drawing.
FAQ
Q: How do I choose between programmatic brushstrokes and diffusion generation? A: Choose the former for controllability and auditability, the latter for speed. Q: Why no undo? A: It is used to test planning ability under one-shot writes. Q: How do I get started with code? A: Implement a canvas array and a round brush first, then add parameters step by step.
