Technical Analysis: How Large Language Models Paint by Simulating Physical Brushes in Code

    This technical analysis explains how a large language model can paint without an image generation model. The model writes Python code that simulates brushes, paint, and canvas, then paints stroke by stroke in a virtual environment. The article covers how the model models brush properties and stroke paths, how it plans strokes when undo is not available, how it corrects errors using visual feedback, and what the approach means for developers.

    In today’s AI field, image generation has made remarkable progress. Mainstream approaches typically use diffusion models, which gradually denoise random noise to produce the final image pixels. However, this direct generation of pixel matrices often lacks awareness of the physical process of painting itself. Recently, a cutting-edge AI research team demonstrated an unconventional approach to AI image generation. Instead of calling an image generation model, a large language model writes Python code to simulate real brushes, paints, and canvases, and paints stroke by stroke in a virtual environment. Turning artistic creation into a code engineering task offers developers a new perspective.

    1. Code-Level Abstraction and Simulation of Physical Properties

    Traditional image generation models focus on what to draw. Code-based simulated painting focuses more on how to paint. In this approach, the large language model first abstracts the physical elements of painting into executable code logic.

    1. Digital definitions of brushes and paint: The Python program written by the model is essentially a simulated painting engine. In this engine, a brush is no longer a simple pixel-filling tool. It is an entity with physical properties. The code defines the brush width, texture, paint wetness, and canvas roughness. Together, these parameters determine how each stroke spreads on the canvas and how its edges look.
    2. Fine-grained control of paths and coordinates: A painting consists of many individual stroke instructions. The model outputs coordinates for each stroke and plans the movement path of the brush. For example, when painting a bird at sunrise, the model’s first stroke may use a specific hex color code, a brush width of 90 pixels, and five slightly wobbly path points.
    3. Deliberate human-like jitter: The model adds a random wobble of about 7 pixels in the code. This design reflects an understanding of human physiology. Muscle tremors and other factors keep a human hand from drawing perfectly straight lines. By adding this kind of imperfection, the artwork looks more realistic and lively.

    The following illustrative code shows how the model defines a single stroke:

    1. class BrushStroke:
    2. def __init__(self, color, width, path_points, jitter=7):
    3. self.color = color # Color code, e.g. '#30346a'
    4. self.width = width # Brush width, e.g. 90
    5. self.path = self._apply_jitter(path_points, jitter) # Apply human-like jitter
    6. self.wetness = 0.8 # Paint wetness
    7. self.canvas_texture = "rough_canvas_01" # Canvas texture mapping
    8. def _apply_jitter(self, points, jitter):
    9. # Simulate the natural jitter of a human arm
    10. return [(x + random.uniform(-jitter/2, jitter/2),
    11. y + random.uniform(-jitter/2, jitter/2)) for x, y in points]
    12. def render(self, canvas):
    13. # Call the simulation engine to render this stroke on the canvas. Once drawn, it cannot be undone.
    14. canvas.draw_stroke(self)

    2. Stroke Planning and the Challenge of Irreversible Execution

    Code-based painting is very difficult for a large language model to execute. A photorealistic work may require hundreds of thousands of simulated strokes. One reported case drew a shopping cart in a parking lot using about 700,000 strokes. These works do not rely on external image models, and they do not use pre-rendered or traced reference images as a base layer.

    1. Fine-grained planning: With so many strokes, the model needs strong high-level planning and precise low-level execution. It must conceptually divide the full image into layers such as background, subject, light and shadow, and details, then turn each layer into a sequence of specific strokes. The code often reaches 1,000 to 2,000 lines and contains complex control logic.
    2. Constraint of irreversibility: Many digital drawing programs support undo. This simulation often does not. Once a stroke lands on the canvas, it cannot be removed. The model therefore has very little margin for error, and every coordinate it outputs must be calculated carefully. This constraint pushes the model to reason more deeply before it outputs code, simulating the execution in advance to make sure each stroke lands in the right place.

    3. Dynamic Error Correction Loop Based on Visual Feedback

    Although strokes cannot be undone, the model is not limited to blind execution. During multi-round painting, it shows an observe-and-correct loop similar to human behavior.

    1. State awareness and error detection: While painting, the model observes the current state of the virtual canvas and compares it with the intended goal. For example, it can notice when the bird’s back is drawn too thin or when lines in some areas look messy.
    2. Overlay correction strategy: Because strokes cannot be undone, the model corrects mistakes by adding new strokes. This closely resembles how oil and watercolor painters work, adjusting shapes and colors by covering and layering paint. The model plans new overlay paths and color mixes to gradually bring the visual result back on track.

    This closed feedback loop shows that the model does more than generate static code. It can also perform multimodal or stateful reasoning in a dynamic execution environment and adjust its next action continuously.

    4. Building an Artist Persona and Developing an Independent Style

    Large language models often face criticism in art creation because their work tends to imitate existing art styles and lacks originality. To address this, researchers explored using persona settings to guide stylistic innovation.

    1. Injecting fictional backgrounds: Instead of imitating a specific painter’s brushwork, the model is given an artist persona with a fictional life history and distinctive aesthetic preferences. This deep role-play leads the model to consider the background of this persona when it generates stroke code. As a result, the overall composition and the fine brushwork share an internal consistency.
    2. Guidance through text feedback: Researchers evaluate the visual output with text feedback and use it to guide the model in adjusting brush parameters and the internal logic of the painting engine. For example, if the feedback says the color contrast is too flat, the model may adjust its paint blending algorithm or brush transparency in the next version of the code. Through this feedback-based reinforcement learning process, the model gradually develops an artistic style that is relatively independent, stable, and not easily classified under a single existing school.

    5. Implications for Developers and Engineering Practice

    Using a large language model to simulate physical brushes through Python code matters well beyond image generation. For developers, it shows the potential of AI in breaking down complex tasks, simulating physical systems, and closing automation loops.

    1. Code-level restructuring of complex systems: The model turns a highly abstract artistic goal into more than a thousand lines of code with physical logic. When developing automation, robot control, or simulation systems, developers can use this ability to break high-level requirements into fine-grained execution instructions.
    2. Potential in cloud-native architectures: In modern cloud development, developers can use compute and model inference services from platforms such as Baidu AI Cloud to build similar complex agents. By combining a large language model’s planning capability with a containerized cloud execution environment, they can automate data analysis, code refactoring, and even industrial simulation testing. The model’s error correction under irreversible conditions also suggests ways to build highly robust automated operations pipelines.

    In summary, using code to simulate physical brushes and painting stroke by stroke, without traditional image models, marks a shift from result-oriented to process-oriented creation. This approach expands the boundaries of AI art. It also shows that code generation based on large language models can handle complex logic, physical abstraction, and dynamic correction. It offers a useful reference for future automated engineering and agent development.