Training AI to Paint with Code (2026 Guide)

Training AI to paint with code means using an AI chat tool to write and repeatedly refine a small program — usually in p5.js or Processing — that draws a generative painting on a canvas, instead of typing a prompt into an image generator. You're not training a model's weights; you're training the output through rounds of plain-English feedback on the code it writes.

Short answer: To train AI to paint with code, open Claude or ChatGPT, describe a generative art style in plain English, and let it write p5.js code that renders in a live canvas (Claude Artifacts) or a free editor (editor.p5js.org). Run it, then give feedback like "more chaotic" or "warmer palette" and ask it to revise the code. Repeat 5–10 rounds until the output matches what you pictured.

Cursor homepage — screenshot of cursor.com
Cursor homepage — screenshot of cursor.com

I spent a weekend testing this the way most people actually try it: no prior p5.js experience, just Claude open in one tab and the free p5.js web editor in another, describing paintings in plain English and seeing how many rounds it took to get something I'd actually want to look at. Here's what worked, what the tools can't do yet, and the mistakes that wasted the most time before I stopped making them.

What you'll need

An AI chat tool that can write and run code in front of you — Claude (any plan, including Free) with Artifacts turned on, or ChatGPT with Canvas. You don't need to install anything for the Claude route, since Claude Artifacts renders p5.js sketches directly in its side panel. If you'd rather work in a dedicated canvas, the free p5.js web editor at editor.p5js.org runs entirely in the browser, and you paste whatever code your AI tool writes into it. No drawing skill required — the whole point is that the AI writes the code that draws.

Step-by-step: Training AI to paint with code

1. Pick your canvas

Claude Artifacts is the fastest path if you already have a Claude account: turn on "Code execution and file creation" in Settings, and any p5.js code you ask for opens in a live, editable panel next to the chat. If you're using ChatGPT, Canvas can write the code, but you'll need to copy it into the p5.js web editor to actually see it render — ChatGPT doesn't preview p5.js sketches inline the way Claude Artifacts does.

2. Describe the painting, not the code

Skip technical language on your first prompt. Describe what you want to see: "a generative painting of overlapping translucent circles in warm sunset colors, some drifting slightly like they're breathing." Let the model pick the p5.js functions. In my testing, prompts that described a mood or reference (like a real painter's style) produced more interesting first drafts than prompts that specified exact RGB values or coordinates.

3. Run it and actually look at the first draft

Your first result will usually be too neat — evenly spaced shapes, predictable colors, nothing that reads as "painted." That's normal. It's the starting point for the feedback loop, not the finished piece.

4. Give feedback in plain language, one change at a time

This is the actual "training" step, and it's where most of the real work happens. Say "make the spacing irregular instead of a grid," or "add more variation in circle size," or "the palette feels cold — make it warmer." I got noticeably better results asking for one change per round instead of five at once — stacking requests made the model overcorrect and lose the parts that were already working.

5. Ask for controlled randomness once you like the shape of it

Once the composition feels right, ask the AI to add a randomSeed() value or expose variables (color count, shape density, speed) so you can regenerate variations without losing the version you liked. In my test, this was the single most useful request — it turned one painting into a small family of them I could pick from.

6. Save the code and the seed, not just the image

Export the canvas as a PNG for the finished look, but keep the actual .js file and the seed value too. Unlike a prompt to an image generator, the code is fully reproducible — the same seed on the same code produces the identical painting every time, which is not true of diffusion-based image tools.

7. Iterate across sessions if you want to keep developing a style

Neither Claude nor ChatGPT remembers your generative art style between separate conversations by default. If you're building on a look over several sessions, paste your best working code back in at the start and say "here's a piece I like — build on this style" rather than starting from a blank prompt each time.

Example prompts you can copy

These are close to what I actually typed while testing the steps above:

  • "Write p5.js code for a generative painting: overlapping translucent circles in a warm sunset palette, irregular spacing, some drifting slowly like they're breathing."
  • "Make the color palette cooler and add more size variation between the largest and smallest shapes."
  • "Add a randomSeed() variable at the top so I can regenerate variations, and expose shape count and speed as adjustable numbers."
  • "Rewrite this as flowing brush-stroke lines instead of circles, keeping the same color palette: [paste your current code]."
  • "This looks too much like a grid — add randomness to the position so it reads as hand-placed, not generated."

State the mood or reference first, then react to what you actually see rather than guessing what will work — that back-and-forth is the difference between a painting you'd hang somewhere and one you close the tab on.

Common mistakes to avoid

The one I made first: expecting a single prompt to produce a finished piece, the way a good Midjourney prompt sometimes does. Code-based generative art almost never works that way — the value is in the iteration loop, not the first output. Second, stacking too many change requests in one message; the model tends to overcorrect and undo parts you liked, so change one thing at a time. Third, forgetting to ask for a randomSeed() early — without it, you can't reproduce a version you liked, and regenerating just gives you a different random result. Fourth, treating this like actual machine learning training and expecting the AI to "remember" your style automatically across sessions — it doesn't, unless you paste your working code back in. Fifth, picking ChatGPT for the live-preview workflow and being surprised it doesn't render p5.js inline — it writes solid code, but you need the p5.js editor or Claude Artifacts to actually see it paint anything.

Tools compared for this workflow

Tool Live preview? Price Best for
Claude Artifacts Yes, inline p5.js rendering Free plan included; Pro $17–20/mo for higher limits Fastest loop — write, see, revise without leaving the chat
ChatGPT + Canvas No — code only, no p5.js render Free tier writes code; Plus is $20/mo Strong code quality, but needs a separate editor to view it
p5.js web editor (editor.p5js.org) Yes, dedicated canvas Free, open source Pasting AI-written code when you want a bigger, dedicated workspace

Claude's free plan already includes Artifacts and code execution, confirmed on Claude’s pricing page as of August 25, 2026 — you don't need Pro just to try this. ChatGPT Plus runs $20/month per OpenAI’s Help Center, and it's a fine choice for the code itself, but pair it with the free p5.js editor since Canvas won't show you the painting directly.

Tools that make this easier

If you're new to Claude's side-panel workflow, my how to use Claude Artifacts guide covers the setup and the version-history habits that saved me from losing working drafts. For anything that outgrows a single p5.js file — a generative art tool with a real interface, or a project you want to package as an app — my best AI tool for code roundup and how to use Cursor AI guide both cover the next step up. If you'd rather try this in an editor-based tool instead of a chat panel, ChatGPT alternatives for coding covers the wider field, and how to use ChatGPT for free is worth reading if you want to test the code-writing side without paying anything yet. Deciding which model writes cleaner code in the first place? Claude vs. ChatGPT tested both directly on real tasks.

My take

Training AI to paint with code is less about the AI and more about the loop you run it through — plain-English feedback, one change at a time, and a seed value so you can keep what works. Claude Artifacts is the easier starting point because you see the painting the moment it's written, with no separate editor needed, and it's free to try. ChatGPT writes comparably good p5.js code but makes you leave the chat to see it, which slows down the iteration that actually makes this fun. Either way, budget an evening, not ten minutes — the first draft is never the piece you keep.

Frequently Asked Questions

Is training AI to paint with code free?

Yes, entirely. Claude's free plan includes Artifacts and code execution, and the p5.js web editor at editor.p5js.org is free and open source with no account required. You only need a paid plan if you want higher usage limits than the free tiers allow.

How long does it take to train AI to paint with code?

Getting a first working sketch takes a few minutes. Getting a painting that actually looks intentional took me 5–10 rounds of feedback in testing, which is closer to 20–30 minutes for a single piece once you're used to the loop.

What is the easiest way to do this?

Start in Claude with Artifacts turned on, since it renders p5.js inline without a separate editor. Describe a mood or style in plain English, then react to the actual output one change at a time instead of trying to write a perfect prompt up front.

Do I need to know how to code?

No. You need to be able to describe what you want to see and react honestly to what the AI draws. Reading the code helps you spot what to ask for next, but you never have to write it yourself.

Can I reproduce the same painting later?

Yes, if you save the code and ask for a randomSeed() value. The same seed on the same code produces an identical result every time, unlike prompting an image generator, where the same words rarely produce the same image twice.