Last active
February 27, 2017 00:48
-
-
Save jrc03c/5274af3aa9ffd692dfd19e1fc5173515 to your computer and use it in GitHub Desktop.
More spirographs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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