// Simin Li
// Section C
// siminl@andrew.cmu.edu
// Project 4
var X1
var Y1 //coordinates of first point on line segment
var X2
var Y2 //coordinates of second point on line segment
function setup() {
createCanvas(640, 480);
background("LightSalmon");
X1 = 0;
Y1 = 0;
X2 = length / 2;
Y2 = sqrt(3) * length / 2; //use trig to set outer triangle to be equilateral
}
function draw() {
flower(width/ 2, height / 2,240);
strokeWeight(0.3);
flower(width/ 2, height / 2,110);
//draw flowers at width/ 2,height / 2 with "radius" of 240 and 110
noLoop();
}
function halfPetal(x, y, a, sign, length) {
//defines the function halfPetal() which draws half a petal either facing down or up.
//x,y determines the left tip of petal
//a dtermines the radians rotated
//sign dtermines whether petal is facing up or down
//length determines the length of petal
push();
X1 = 0;
Y1 = 0;
X2 = length / 2;
Y2 = sign * sqrt(3) * length / 2; //reset the coordinates of point 1 and point 2 before loop
gapX = length / 60; //the difference of X values between two adjacent starting points and end points
gapY = sqrt(3) * length / 60;//the difference of Y values between two adjacent starting points and end points
translate(x,y);
rotate(a);
for(var i = 0; i < 31; i ++){
line(X1, Y1, X2, Y2);
X2 = X2 + gapX;
Y2 = Y2 - gapY * sign;
X1 = X1 + gapX;
Y1 = Y1 + gapY * sign;//connect the dots to form a curve
}
pop();
}
function flower(centerX,centerY,length){
//defines the function flower() which draws a flower at centerX,centerY with petal length of length
stroke(223,40,62);
halfPetal(centerX,centerY,(PI / 3), 1,length);
halfPetal(centerX,centerY,2 * PI / 3 + (PI / 3), 1,length);
halfPetal(centerX,centerY,4 * PI / 3 + (PI / 3), 1,length);
halfPetal(centerX,centerY,(PI / 3) , -1,length);
halfPetal(centerX,centerY, 2 * PI / 3 + (PI / 3), -1, length)
halfPetal(centerX,centerY, 4 * PI / 3 + (PI / 3), -1,length);
//draw pink flower by combing top and bottom petal together and rotating
stroke(35,66,26);
halfPetal(centerX,centerY,0, 1,length);
halfPetal(centerX,centerY,2 * PI / 3 , 1,length);
halfPetal(centerX,centerY,4 * PI / 3 , 1,length);
halfPetal(centerX,centerY, 0 , -1,length);
halfPetal(centerX,centerY, 2 * PI / 3 , -1,length);
halfPetal(centerX,centerY, 4 * PI / 3 , -1,length);
//draw green flower with same proceedure
}
I was surprised that straight lines could produce such organic curves. The shapes reminded me of a flower so I made a flower inside a flower.