Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@DouglasAllen
Created February 10, 2017 04:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DouglasAllen/a25a29dd14e5ce4cb72d85e087d8448d to your computer and use it in GitHub Desktop.
Save DouglasAllen/a25a29dd14e5ce4cb72d85e087d8448d to your computer and use it in GitHub Desktop.
// Daniel Shiffman
// http://codingtra.in
// Mathematical Roses
// Video: https://youtu.be/f5QBExMNB1I
// Based on: https://en.wikipedia.org/wiki/Rose_(mathematics)
var d = 8;
var n = 5;
var sliderD;
var sliderN;
function setup() {
createCanvas(400, 400);
sliderD = createSlider(1, 50, 5, 0.1);
sliderN = createSlider(1, 50, 5, 0.1);
}
function draw() {
d = sliderD.value();
n = sliderN.value();
var k = n / d;
background(51);
translate(width / 2, height / 2);
beginShape();
stroke(255);
noFill();
strokeWeight(1);
for (var a = 0; a < TWO_PI * d; a += 0.02) {
var r = 200 * cos(k * a);
var x = r * cos(a);
var y = r * sin(a);
vertex(x, y);
}
endShape(CLOSE);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment