Created
February 10, 2017 04:40
-
-
Save DouglasAllen/a25a29dd14e5ce4cb72d85e087d8448d to your computer and use it in GitHub Desktop.
This file contains 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
// 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