Melbourne Art School
Creative coding3 minute read

10 generative art ideas to code this weekend (number 1 is a 40-year-old one-liner)

Ten classic generative art ideas for beginners, from the 10 PRINT maze and Truchet tiles to flow fields, recursive trees and Lissajous curves, with starter code in p5.js.

A swinging sand pendulum tracing a looping, criss-crossed Lissajous pattern on a dark surface
A sand pendulum tracing a Lissajous figure. Photo: Nevit Dilmen, CC BY-SA 3.0, via Wikimedia Commons.

Key takeaways

  • Generative art uses rules, repetition and chance to make images that can surprise even their maker.
  • Most classic ideas need only a few lines of code.
  • Pick one idea and make ten variations by changing one number at a time.

The fastest way to learn creative coding is to make things. These ten ideas are classics because they’re simple to start and endlessly variable. Try them in the free p5.js Web Editor; new to code? Start with our beginner’s plan.

1.The 10 PRINT maze

In the early 1980s, a one-line program for the Commodore 64 home computer drew an endless random maze from just two characters, a forward slash and a backslash. It became so celebrated that a group of scholars wrote a whole book about it in 2012. Here it is in p5.js: each cell randomly gets one diagonal or the other.

let x = 0, y = 0;
const s = 20;

function setup() {
  createCanvas(600, 600);
  background(243, 242, 238);
  strokeWeight(2);
}

function draw() {
  if (random() < 0.5) line(x, y, x + s, y + s);
  else line(x, y + s, x + s, y);
  x += s;
  if (x >= width) { x = 0; y += s; }
  if (y >= height) noLoop();
}

Try changing s, the cell size, or the 0.5 probability.

2.Truchet tiles

In 1704 the French priest and scientist Sébastien Truchet studied the patterns made by rotating a single square tile split diagonally into two colours. Truchet tiles are a perfect next step from the maze. A later variation uses quarter circles instead of diagonals, producing flowing, river-like curves.

3.From order to disorder

Draw a neat grid of squares, then add a little random offset to each, increasing as you move across the page. Vera Molnár explored this tension between order and chaos for decades, including in her 1974 series (Dés)Ordres.

4.Random walkers

Start a point in the centre and move it one step in a random direction every frame, leaving a trail. Then add a hundred walkers in different colours. Simple rules, rich results.

5.Flow fields

Use Perlin noise to give every point on the canvas a direction, then release thousands of particles that follow it. The result looks like hair, smoke or wind.

6.Recursive trees

Draw a branch, then from its tip draw two smaller branches at an angle, and repeat. This is recursion, and it’s how many plants actually grow. In 1968 the biologist Aristid Lindenmayer developed L-systems, a way of describing plant growth with rules.

A single computer-generated tree with a white trunk and dense green canopy on a pale grey ground
Alex Gibson, Trees Are Algorithms Too, 2020. A tree is a recursive structure: branches made of smaller branches.

7.Circle packing

Place circles at random and grow each one until it touches another. The page fills with a satisfying, cellular texture. Try limiting the colours to two or three.

8.Lissajous curves

Combine two simple waves at right angles and you get elegant looping figures. The French physicist Jules Antoine Lissajous used them in 1857 to make sound vibrations visible. Lissajous curves are a few lines of code, and changing the ratio between the two waves transforms the shape.

9.Noise landscapes

Draw rows of horizontal lines and push each point up or down with noise. Stack them and you get mountain ridges, sound waves or topographic maps.

A rippling blue-grey generative terrain inside a rounded square on black
Alex Gibson, Displacement no. 19, 2018. A terrain shaped by noise.

10.Instruction drawings, no computer needed

Write a set of rules, such as “draw ten straight lines, each starting where the last one ended, never crossing”, and give it to a friend to draw by hand. Compare the results. Sol LeWitt made whole wall drawings this way, and it’s the clearest way to understand that generative art is about the system, not the tool.

How to turn an idea into a series

  • Change one number at a time and save every version you like.
  • Limit your colours. Two or three good colours beat twenty.
  • Use randomSeed() so you can recreate a favourite result.
  • Export at high resolution and print. Work changes when it leaves the screen.

References and further reading

  1. 10 PRINT CHR$(205.5+RND(1)); : GOTO 10 (book)
  2. Truchet tiles on Wikipedia
  3. Vera Molnár on Wikipedia
  4. Perlin noise on Wikipedia
  5. L-system on Wikipedia
  6. Lissajous curve on Wikipedia
  7. Sol LeWitt on Wikipedia
Alex Gibson, founder of Melbourne Art School, in a black-and-white portrait wearing headphones

Alex Gibson

I’m an artist and creative technologist with a Master of Fine Arts, and the founder of Melbourne Art School. My work moves between pencils, plotters, code and live printmaking performance, and I teach drawing and creative coding in small evening classes in Brunswick.

More about me and the school

Stay curious.

Hear about new classes, workshops, artist talks and creative ideas from our studio.

Unsubscribe anytime. Read our privacy policy.