Skip to content

Instantly share code, notes, and snippets.

@bogoreh
Created March 11, 2021 11:30
Show Gist options
  • Select an option

  • Save bogoreh/c838fbe083b6331bbf062826597c2c36 to your computer and use it in GitHub Desktop.

Select an option

Save bogoreh/c838fbe083b6331bbf062826597c2c36 to your computer and use it in GitHub Desktop.
//converting mode to degrees
angleMode = "radians";
//displaying the slinky on the canvas
var drawSlinky = function(centerX, startY, endY) {
noFill();
colorMode(HSB);
strokeWeight(2);
ellipseMode(CENTER);
var overlap = 0.8;
var space = (endY/overlap - startY)/30;
for (var i = 0; i < 30; i++) {
stroke(i*9, 200, 255);
ellipse(centerX, i*space*overlap + startY, 60, space);
}
};
draw = function() {
background(255);
//applying simple harmonic motion (oscillating)
var y = sin(TWO_PI * frameCount /80);
var m = map(y, -1, 1, 200, 400);
drawSlinky(width/2, 10, m);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment