Algorithmic Art

Algorithmic art is just using code to generate patterns, shapes or animation. p5.js is perfect for this. So here are some additional snippets of code or examples to whet your appetite. try them out for yourself and explore ideas for yourself. Be as creative as you can.

10PRINT

Notes:This is a simple example of some algorithmic code. It is based on an old computer graphics machine and is called 10PRINT. If you change this line of code…

if (random(1) < 0.5) 

to some other fraction e.g. 0.1, or 0.9 you will get different effects. Also experiment with different shapes other than two sloping lines.

let x = 0
let y = 0
let spacing = 20

function setup() 
{
  createCanvas(800, 800)
  background(0)
}
function draw() 
{
  stroke(255)
  strokeWeight(5)
  if (random(1) < 0.5) 
  {
    line(x, y, x + spacing, y + spacing)
  } 
  else 
  {
    line(x, y + spacing, x + spacing, y)
  }
  x = x + spacing
  if (x > width) 
  {
    x = 0
    y = y + spacing
  }
}