Code-Driven Painting: How Programmed Brush Strokes and Physics Simulation Create Artwork
This article explains a code-driven approach to AI image creation. Instead of generating pixels directly as diffusion models do, the system plans individual brush strokes on a virtual canvas and simulates paint behavior, brush motion, and canvas texture. The article covers the stroke-level representation, the wet-paint physics that limit corrections, how the model develops an artistic persona, and how stroke count changes the creative strategy. It also discusses possible applications for developers and the infrastructure these workloads may require.
From Generating Images to Writing Paintings: A Shift in Paradigm
In AI-based visual content generation, diffusion models have long been the dominant approach. These models add conditional information to random noise step by step, then denoise the result to recover a complete image. Their strengths are efficient overall composition and fine texture. However, they are essentially black-box, pixel-level predictions.
A different approach has recently drawn wide attention from developers. Instead of generating an image directly, it writes program code that simulates a real brush moving across a virtual canvas. The code models paint wetness and canvas texture, and it builds the artwork one stroke at a time.
The core idea is to break painting into many independent stroke instructions. The model no longer predicts pixel values. Instead, it plans the starting point, direction, pressure, color, and brush type of each stroke. This requires strong spatial reasoning and an awareness of physical simulation. From a technical standpoint, this is not a simple tool upgrade. It shifts creation from producing a result to constructing a process.
Under the Hood: How Brush Strokes Are Programmed
In traditional computer graphics, brush strokes usually rely on complex particle systems or fluid dynamics calculations. In this new approach, each stroke is converted into structured coordinate data. For example, in a painting of birds at sunrise, the first stroke might be defined as: use paint with color code #30346A, set the brush width to 90 pixels, and move along a path with five slightly wavering points.
The path planning is not a mechanical straight-line interpolation. The model deliberately adds a random wobble of about 7 pixels to each stroke. This is not a technical limitation. It is a deliberate design choice. Human arms, due to muscle control and physical structure, cannot draw perfectly straight lines. These small imperfections are what give hand-painted work its texture. By encoding this human perceptual error into the algorithm, the model comes closer to the behavior of a real painter.
Physical Simulation: Paint, Canvas, and Irreversible Corrections
Unlike the layer concept in digital painting software, this code-driven painting engine is typically set to a “wet painting” mode. Paint spreads and mixes naturally after touching the canvas, and each new stroke physically interacts with the paint already there. As a result, the model cannot erase mistakes by deleting a layer. It must cover or blend errors by adding new strokes over the existing paint.
This mechanism pushes the model toward strategic planning. While painting, the model continuously observes the current state of the canvas, compares it with the target image, and identifies where errors are. For example, if the lines along a bird’s back look too thin and messy, the model does not clear the canvas and start over. Instead, it analyzes the dryness and thickness of the existing paint, then chooses a suitable color and brush to cover and repair the area. This observe, judge, and correct loop turns each piece of work into a dynamic decision process.
Autonomous Style Evolution: From Imitation to Originality
This programmatic approach also produces an unexpected side effect: the artistic style evolves on its own. In early experiments, the generated paintings were often criticized for copying existing art styles too closely. To break through this limit, the research team guided the model to create its own “artist persona” with a fictional background and a consistent creative tendency.
Under this setup, the model derives the tones, stroke force, and composition habits that this fictional artist might prefer, based on an imagined biography. Then, through a text feedback mechanism, the model adjusts the parameters of the painting engine based on how the work turns out. These parameters include the paint dilution ratio and the brush elasticity coefficient. This self-evolving mechanism means the final works are not recombinations of existing styles. They are continuous creations grounded in a character setting, which gives them a distinct visual language.
Compute Resources and Engineering Practice: From 700,000 Strokes to 111 Strokes
In practice, controlling the number of strokes reflects the model’s planning ability and creative intent. In one experiment, the model was asked to paint a shopping cart in a parking lot with photorealistic detail. It completed the work using approximately 700,000 simulated brush strokes. In another experiment, with the limit of “111 strokes only,” the model chose a minimalist style. It deliberately skipped detail accumulation and instead created atmosphere through precise color blocks and stroke direction.
This difference shows that the model can adjust its creative strategy based on task instructions. High-stroke scenes test sustained planning and resource scheduling. Low-stroke scenes test the ability to generalize and abstract. Each painting task is effectively a Python program of 1,000 to 2,000 lines. The program calls specific drawing engine interfaces to initialize the canvas, define brushes, and execute the stroke sequence.
Potential Applications and New Opportunities for Developers
Although this technology is still experimental, its potential uses are starting to take shape. For software developers, the “painting as code” model offers a new paradigm for procedural content generation. In game development, it could generate textures with a handmade quality on demand. In film and visual effects, it could simulate brush effects of specific styles, which may help avoid copyright disputes over assets. For front-end developers, this could mean generating batches of stylistically consistent illustration assets through simple API calls to a “virtual painter.”
From a cloud computing perspective, this kind of compute-intensive task places higher demands on the underlying infrastructure. While painting, the model needs strong CPU and GPU resources for path calculations, and it must keep the canvas state in large amounts of memory. If this technology moves into commercial use, cloud providers may offer dedicated “painting compute instances” with persistent storage for the intermediate states of unfinished paintings. This could support resuming work from checkpoints and distributed collaborative painting.
Conclusion: A Return to the Logic of Painting
In a sense, this code-driven approach returns to the essence of art. It no longer treats an image as a simple matrix of pixels. It redefines the image as the result of a behavior. Every artwork contains countless decisions, and those decisions can be reviewed, reproduced, and optimized through code. For developers, this opens a new door. We no longer teach machines what beauty is only through training data. We write logic that shows machines how to create beauty. This is not just a split in technical direction. It is a deeper engineering exploration of creativity itself.
