Skip to content

Instantly share code, notes, and snippets.

@jrc03c
Last active February 27, 2017 00:48
Show Gist options
  • Save jrc03c/5274af3aa9ffd692dfd19e1fc5173515 to your computer and use it in GitHub Desktop.
Save jrc03c/5274af3aa9ffd692dfd19e1fc5173515 to your computer and use it in GitHub Desktop.
More spirographs.
var n = 7;
var angles, speeds, lengths;
function setup(){
createCanvas(window.innerWidth, window.innerWidth);
background(255);
fill(0, 20);
frameRate(9999);
angles = [];
speeds = [];
lengths = [];
for (var i=0; i<n; i++){
angles.push(0);
speeds.push(random(1) < 0.5 ? (i+1) * (i+1) * -PI/(8*360) : (i+1) * (i+1) * PI/(8*360));
lengths.push(width/((i+1) * 8));
}
}
function draw(){
translate(width/2, height/2);
rotate(-PI/2);
for (var i=0; i<n; i++){
rotate(angles[i]);
stroke(0, 4);
if (i > 0) line(0, 0, lengths[i], 0);
translate(lengths[i], 0);
noStroke();
ellipse(0, 0, 2, 2);
angles[i] += speeds[i];
}
if (angles[0] >= TWO_PI || angles[0] <= -TWO_PI) noLoop();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment