How Large Language Models Simulate Brush Painting with Code
This article explains how large language models can write code that paints on a digital canvas one stroke at a time. It compares this approach with diffusion-based image generation, describes the plan-execute-observe-correct loop, and outlines the possible value and risks for robot control. The approach is still experimental, and the source material provides no quantitative evaluation.
Introduction
Diffusion models generate images by starting from random noise and removing it step by step until a complete image appears. Another approach has a large language model write a program that paints on a digital canvas one stroke at a time. This process is closer to how people paint, and it is easier to break down and inspect.
This approach is mainly in the research and demonstration stage. It is not a general capability of large language models. The source material does not name a specific research paper or project, so details from the demonstrations, including stroke counts and parameter values, should be checked against the original paper or project documentation. This article focuses on how the approach works and what it may offer for robot control.
How Code Simulates the Physical Properties of a Brush
The two approaches differ in the following ways.
| Dimension | Diffusion model | Code-based stroke simulation |
|---|---|---|
| Output | A full pixel image | An executable drawing program |
| Control granularity | Probability distributions over pixels | Parameters such as coordinates, color, and brush width |
| Interpretability | Low, and hard to trace step by step | High, since each stroke corresponds to an explicit instruction |
| Typical failure modes | Structural distortion and loss of detail | Code errors and parameters outside a reasonable range |
| Suitable scope | Static image generation | Tasks that require controllable or reproducible processes |
In code-based simulation, the generated program usually contains many strokes. Each stroke specifies parameters such as color, width, and moisture. The rendering engine then calculates the final visual result from these parameters. The following illustrative pseudocode shows the basic structure of a stroke class:
import randomclass BrushStroke:def __init__(self, color, width, moisture):self.color = color # Color, for example "#30346a"self.width = width # Brush width in pixelsself.moisture = moisture # Paint moisture, ranging from 0 to 1self.path_points = []def add_point(self, x, y):# Add random jitter at each path point to simulate the fact that a human arm# cannot draw perfectly straight lines# Jitter range is ±3.5 pixels, giving a total swing of about 7 pixelsjitter_x = x + random.uniform(-3.5, 3.5)jitter_y = y + random.uniform(-3.5, 3.5)self.path_points.append((jitter_x, jitter_y))def render(self, canvas):# canvas.draw_path is a placeholder interface that must be implemented by a specific rendering enginecanvas.draw_path(self.path_points, self.color, self.width, self.moisture)
This code only illustrates the idea and cannot run as written. canvas.draw_path is an assumed interface. A real system would replace it with an actual rendering library. The 3.5-pixel jitter is a parameter value. The source material does not explain how it was chosen, so it should be tuned to the canvas resolution and the desired visual result.
The effects of paint moisture and canvas texture are usually calculated by the rendering engine, not set directly by the model. The model supplies the parameters, and the engine reproduces the physical effects. This division keeps the model’s output simple and makes the rendering component easier to debug on its own.
How the Closed Loop Corrects Errors
The core cycle of this method is plan, execute, observe, and correct. The model first plans the overall composition. It then executes a segment of strokes, observes the current state of the canvas, and, if it finds a deviation, plans new strokes to correct it.
One point is easy to misread. Undo in digital painting software is simple. The “irreversible” setting described in the source material is a design choice of the simulation system. The rendering engine can be configured to disable undo, so the model must keep working from the current state of the canvas. This makes the simulation closer to real painting. It also forces the model to learn to correct existing results instead of starting over.
The source material gives two examples. In the first, a sunrise scene includes birds. If the lines on a bird’s back are too thin and messy, the model does not repaint the whole bird. It covers the area with thicker strokes and uses the bristle marks at the edges to suggest fluffy feathers. In the second, lighting has blurred the objects on a tabletop. The model reorders its drawing priorities and uses new instructions to fill in the details of those objects. These examples show the direction of the correction ability, but the source material does not provide quantitative evaluations of the results before and after correction.
For the “observe” step to work, the model needs to receive the rendered image as multimodal visual input. Code text alone does not show whether the picture matches the intended result. A complete system therefore usually needs three things: a visual feedback channel, an executable rendering environment, and an undo restriction set by configuration.
What Can Robot Control Learn From This?
Painting on a canvas has parallels with robotic work. Both involve continuous sequences of actions, irreversible consequences, and environmental disturbances. The three points below are labeled by how well supported they are.
Segmented planning (well supported)
Breaking a large goal into subtasks, and generating each next instruction based only on the current state, can apply directly to robot task orchestration. The robot does not need to plan all of its actions at once. Even so, the trajectory for each segment must be checked against limits on speed, force, and workspace before it is sent to the actuators.Perception-action loop (inferred)
The model compares the actual result on the canvas with the target result. A robot can do the same by using cameras or force sensors to collect its state and compare it with the expected state. When a deviation appears, the system generates a corrective action. This matches needs in industrial settings. However, sensor noise, calibration error, and signal delay all affect the comparison, and the results depend on the system configuration.Multi-agent constraints (depends on system configuration)
In a painting, the actions of two figures must satisfy constraints such as body contact and hand use. For robots, the equivalent is avoiding collisions and synchronizing motion in multi-arm cooperation. A language model can understand what these constraints mean, but it cannot guarantee a collision-free path. Collision detection and kinematic solving must be handled by dedicated algorithms or modules. The model can only serve as a higher-level coordinator.
Risks to Consider Before Deployment
- Safety: Model output can be wrong. The system needs hardware-level limits on speed and torque, workspace boundaries, and a physical emergency stop. It should be thoroughly validated in simulation before it runs real tasks.
- Latency: Inference by a large model usually takes much longer than the control cycle of a servo controller. A common practice is to let the large model handle high-level planning while a real-time controller handles execution. Actual latency must be measured on the target hardware.
- Perception: Sensor noise, calibration drift, and occlusion can all cause misjudgments. An incorrect observation leads directly to an incorrect correction.
- Simulation-to-reality gap: A virtual canvas has no friction, vibration, or load variation. Good performance in simulation does not mean a real robot will be equally reliable.
- Cost: Long-context inference and continuous visual feedback require stable computing resources. Cost should be evaluated early in a project.
FAQ
What sensors are needed?
This depends on the task. Vision tasks usually require cameras. Contact tasks, such as assembly or polishing, usually require force or torque sensors. Sensor choice should be based on the observation accuracy the task needs.
How should control frequency be chosen?
High-level planning can run at a lower frequency. Low-level servo control needs a high frequency and is usually handled by a hardware controller. The exact frequency should be determined after measuring latency on the target hardware.
How can safety fallbacks be implemented?
Add a validation layer between the model output and the actuators to check the speed, force, and position range of every instruction. Keep an independent physical emergency stop, and define a clear fallback action for failures, such as stopping and waiting for human confirmation.
What are common failure modes?
The main ones are parameters outside a reasonable range, misread observations, errors that accumulate across multi-step plans, and mismatches between the simulated and real environments. These failures usually need to be located through logging and replay.
Conclusion
Painting with code through a large language model shows a promising technical direction. Its approach to breaking down long tasks and using observations to correct results is relevant to robot control. However, the demonstration details in the source material lack a paper or project reference and quantitative evaluation. Whether this method can be used on real robots must be tested through experiments on specific tasks. Before citing this work, add the source of the original research and the experimental conditions.
