Skip to content

Instantly share code, notes, and snippets.

@jrc03c
Created February 26, 2017 16:00
Show Gist options
  • Save jrc03c/bd5b18c7e332e51bd036290a889a5e5f to your computer and use it in GitHub Desktop.
Save jrc03c/bd5b18c7e332e51bd036290a889a5e5f to your computer and use it in GitHub Desktop.
A Spirograph
var n = 4;
var angles;
var speeds;
var lengths;
function setup(){
createCanvas(window.innerWidth, window.innerHeight);
stroke(0, 10);
fill(0);
frameRate(99999999999);
angles = [];
speeds = [];
lengths = [];
for (var i=0; i<n; i++){
angles.push(0);
}
for (var i=0; i<n; i++){
speeds.push((i+1) * PI/180);
}
for (var i=0; i<n; i++){
lengths.push(width/((i+1)*4));
}
}
function draw(){
translate(width/4, height/2);
for (i=0; i<n; i++){
stroke(0, 10);
line(0, 0, lengths[i], 0);
translate(lengths[i], 0);
rotate(angles[i]);
noStroke();
ellipse(0, 0, 2, 2);
angles[i] += speeds[i];
}
if (angles[0] > TWO_PI) noLoop();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment