Getting Started with Generative Art
Generative art is artwork created with code. Instead of moving a brush or pen, you write rules and let the computer produce visuals based on those rules. Sometimes the output surprises you. Sometimes it blows your mind. That unpredictability is the whole point - you build the system, and the system builds the art.
The concept has been around since the 1960s when artists first fed instructions into mainframes. But the tools available today make it wildly accessible. You do not need a computer science degree or any art training. You just need curiosity and a text editor.
Why p5.js Is the Best Starting Point
p5.js is a JavaScript library built specifically for creative coding. It handles all the annoying canvas setup and gives you simple functions for drawing shapes, colors, and animations. The learning curve is gentle, the community is massive, and you can see results in seconds.
Head to editor.p5js.org and you have a browser-based editor ready to go. No installations, no configuration. Write code on the left, see art on the right.
Your First Sketch in 20 Lines
Here is a sketch that creates a field of randomly colored circles. Paste this into the p5.js editor and hit play:
function setup() {
createCanvas(600, 400);
background(10);
noStroke();
for (let i = 0; i < 200; i++) {
let x = random(width);
let y = random(height);
let size = random(5, 40);
let r = random(100, 255);
let g = random(50, 200);
let b = random(150, 255);
fill(r, g, b, 150);
circle(x, y, size);
}
}Every time you run it, you get a different composition. That is generative art at its core - same rules, different outcomes. The random() function introduces variation, and the loop creates repetition with differences. Those two forces together produce visuals that feel organic.
The Building Blocks: Randomness, Noise, and Iteration
Randomness
random() gives you pure chaos. Values jump around with no relationship to each other. Good for scattering elements, picking colors, or creating texture. But pure randomness can feel noisy and harsh.
Perlin Noise
noise() is the secret weapon of generative art. Unlike random(), it returns values that flow smoothly. Think of it like rolling hills instead of jagged peaks. Use it for movement that feels natural, terrain generation, organic color gradients, or anything where you want smooth variation over time or space.
function draw() {
background(10, 10);
for (let x = 0; x < width; x += 10) {
let y = noise(x * 0.01, frameCount * 0.01) * height;
fill(0, 240, 255, 100);
circle(x, y, 8);
}
}Iteration and Recursion
Loops create repetition. Nested loops create grids. Recursion creates fractals. Most generative art comes from some form of repeated operation with small variations at each step. A tree is just a line that splits into two lines that each split into two more lines. A city skyline is a loop that draws rectangles with random heights.
From Static to Animated
p5.js gives you a draw() function that runs 60 times per second. Use it to animate your generative systems. Particles can drift, colors can shift, shapes can grow and shrink. Adding frameCount to your noise calculations creates smooth animation almost for free. The setup() function runs once at the start, draw() runs forever after that. Anything you want to move goes in draw().
Where to Go From Here
Shaders (GLSL)
When you want to push millions of pixels at 60fps, shaders are the answer. They run on the GPU and can produce effects that would be impossibly slow in JavaScript. Start with fragment shaders on ShaderToy to experiment without setup.
3D with Three.js or p5 WEBGL
p5.js has a WEBGL mode that lets you work in 3D with the same friendly API. Three.js gives you more control for complex 3D scenes. Procedural geometry, particle systems, and generative landscapes all become possible.
Audio-Reactive Art
Connect your visuals to sound using the Web Audio API or p5.sound. Map frequency data to size, color, or movement. The result is art that dances to music in real time. Check out our audio visualizers guide for a deeper dive.
Resources and Community
- p5.js Reference - official docs
- The Coding Train - Dan Shiffman's YouTube channel is the gold standard for creative coding tutorials
- OpenProcessing - community gallery where you can study and remix other people's sketches
- Our generative art with JavaScript tutorial goes deeper into Canvas API techniques
The best advice for getting started is to just start. Open the p5.js editor, type something, see what happens. Change a number. See what changes. Break things on purpose. Generative art rewards curiosity more than expertise, and the gap between beginner and making something genuinely beautiful is shorter than you think.