sketch
//Audrey Zheng
//Section A
//audreyz@andrew.cmu.edu
//Project-07
function setup() {
createCanvas(400, 600);
}
function draw() {
background(81,60,85);
push();
translate(width / 2, height / 3);
drawHypotrochoid();
drawHypocycloid();
drawEpicycloid();
pop();
drawFlower(40,20);
}
function drawFlower(x,y) {
translate(x, y);
drawHypotrochoid();
drawHypocycloid();
drawEpicycloid();
}
function drawHypotrochoid() {
var x;
var y;
var a = 100; //radius
//var a = map(mouseX,0,width, 50,90);
var b = 20; //spirograph radius
//var b = map(mouseX,0,width,5,20);
//distance pen to center of spirograph
var h = map(mouseX, 0, width, 40,60);
//var h = map(mouseX, 0, width, 40,60);
angleMode(DEGREES);
stroke(189,230,137);
fill(82,82,115);
beginShape();
for (var t = 0; t < 360; t++) {
x = (a - b) * cos(t) + h * cos(((a - b)/b) * t);
y = (a - b) * sin(t) - h * sin(((a - b))/b * t);
vertex(x,y);
}
endShape(CLOSE);
}
function drawHypocycloid() {
var x;
var y;
var a = 50; //radius
//var a = map(mouseX,0,width, 50,90);
var b = 10; //spirograph radius
var n = a/b;
angleMode(DEGREES);
stroke(98,210,159);
fill(57,138,166,70);
beginShape();
var multiple = map(mouseY,0,height, -1,1)
for (var phi = 0; phi <360; phi ++) {
x = (a/n) * ((n-1) * cos(phi) - cos((n-1) * phi));
y = (a/n) * ((n-1) * sin(phi) + sin((n-1) * phi));
vertex(multiple *x,multiple *y);
}
endShape(CLOSE);
}
function drawEpicycloid() {
var x;
var y;
var a = 40; //radius
//var a = map(mouseX,0,width, 50,90);
var b = 5; //spirograph radius
angleMode(DEGREES);
beginShape();
var multiple = map(mouseY, 0, height, 1,2);;
for (var phi = 0; phi <360; phi ++) {
x = (a+ b) * cos(phi) - b * cos(((a + b)/b) * phi);
y = (a + b) * sin(phi) - b * sin(((a+b)/b) * phi);
vertex(multiple *x, multiple *y);
}
endShape(CLOSE);
}