Training AI to Paint with Code: A Technical Deep Dive into Procedural Generative Art

Training AI to generate executable drawing code instead of pixels — a new paradigm for interpretable, vector-native, human-collaborative art creation.
This article examines the technical direction represented by the "Training AI to Paint with Code" project: training AI to produce drawing code rather than outputting pixels directly. Compared to diffusion models like Stable Diffusion, the code-based approach offers three key advantages — transparent and controllable creative processes, vector output with infinite resolution, and compact files that are easy to edit and iterate on. On the challenge side, the article highlights three core difficulties: scarcity of training data, building the reasoning bridge from visual goals to code logic, and designing closed-loop training with rendering feedback. Ultimately, the article argues that having AI output structured, executable code better fits how humans collaborate and iterate than producing static pixel artifacts — making it a compelling direction in the evolution of generative AI.
When AI Meets Procedural Art
A project called "Training AI to Paint with Code" recently sparked discussion on Hacker News. It explores a thought-provoking premise: instead of having AI generate pixel-level images directly, what if we trained AI to write code that draws artwork? This approach cleverly combines generative AI with procedural art (Generative Art), opening a new window into the world of AI-driven creativity.

Unlike mainstream diffusion models (such as Stable Diffusion and Midjourney) that output bitmaps directly, this "painting with code" approach trains AI to generate drawing instructions or programs, which are then executed by a rendering engine to produce the final image. This means the AI's "artwork" is fundamentally a readable, editable, and reproducible piece of code.
Why Have AI Paint with Code?
Interpretability and Control
Traditional image generation models are classic "black boxes" — you feed in a prompt, you get an image out, but the decision-making process in between is nearly impossible to understand or intervene in. When AI expresses painting through code, however, the creative process becomes transparent. Every line and every color block corresponds to explicit code logic, allowing creators to directly tweak parameters to fine-tune results.
Infinite Resolution and Vector Properties
Code-generated graphics typically have vector characteristics — no matter how far you zoom in, the image stays crisp and sharp, free from the blurriness or pixelation that comes with scaling up a bitmap. For design assets that need to work across different sizes and contexts, this is a natural advantage.
File Size and Editability
A drawing script is typically only a few KB in size, yet it can render complex, stunning visuals. Compared to high-resolution bitmaps that often run several MB, code-based artwork is far more efficient to store and transmit. Designers can also edit these "paintings" like text, enabling rapid iteration.
Core Technical Challenges
Where Does Training Data Come From?
Teaching AI to paint with code first requires a large number of paired "code–image" training samples. This kind of data is far scarcer than ordinary "text–image" pairs. The project needs to build or collect enough procedural artwork to help the model understand the mapping between code structure and visual output.
Reasoning from Visual Goal to Code Logic
The hardest part is getting the model to build a reasoning chain from "I want it to look like this" to "what code should I write to achieve that." This requires the model to not only understand visual aesthetics, but also master programming language syntax and drawing API usage — essentially a deep fusion of visual understanding and code generation.
Closed-Loop Training with Rendering Feedback
An ideal training pipeline should include rendering feedback: the AI generates code, the rendering engine executes it to produce an image, and that image is compared against the target to iteratively optimize the code generation strategy. This closed loop allows the model to "see" the actual output of its own code and continuously improve its results.
Value and Application Prospects
Although this project is still building momentum in the community, the technical direction it represents is worth watching closely. Procedural generative art is itself a classic branch of computer graphics, and injecting modern AI capabilities into it could give rise to entirely new creative paradigms.
For developers, tools like this mean being able to describe requirements in natural language and having AI generate drawing code that can be integrated directly into a project. For artists, painting with code offers a new mode of human-machine collaboration — AI handles the generative scaffolding while humans manage creative refinement and artistic direction.
At a deeper level, having AI express creativity through code rather than pixels is really an exploration of a fundamental question: what should generative AI output? Producing executable, structured code may align better with how humans collaborate and iterate than producing a static, finished artifact.
Conclusion
While "Training AI to Paint with Code" is still a relatively niche exploratory project, it touches on an important question in the evolution of generative AI: how can AI creativity be presented in a more controllable, interpretable, and collaborative form? As code generation models continue to improve, there's good reason to expect more projects that blend AI capabilities with procedural creation — bringing new possibilities to the fields of design and art.
Related articles

Supply Chain Hardware Implants: The Most Dangerous Security Threat You're Overlooking
A deep dive into supply chain hardware implant attacks: how they work, historical cases, and defense strategies. Learn why hardware backdoors are nearly undetectable and how to build a zero-trust defense.

Apple M6 and M5 Ultra Chips Unveiled: What the Major AI Performance Boost Really Means
Apple launches M6 and M5 Ultra chips with dramatically enhanced Neural Engine and on-device AI performance. A deep dive into architecture upgrades, unified memory, and real-world impact.

Fine-Tuning LLMs to Mimic Real Human Chat Styles: A Guide to Building Emotion-Aware Datasets
How to fine-tune an LLM to mimic real human chat styles? This guide covers emotion labeling, context-aware datasets, LoRA fine-tuning, and iterative optimization.