xxxxxxxxxx
75
let angle = 30;
let shape = 1;
let size = 80;
let pastFlower = [];
function setup() {
createCanvas(400, 400);
angleMode(DEGREES);
shape = random([0,1]);
size = 60 + int(random(100))
}
function draw() {
background("#F8F8E8");
rectMode(CENTER);
textFont("Courier New");
fill(121, 173, 220);
noStroke();
textSize(15);
text("Mouse Press to make your flowers bloom",25,350);
// move origin to the mouse position so the loop will draw rotation around the cursor point
translate(mouseX,mouseY);
if (mouseIsPressed){
drawFlower();
}
}
function drawFlower(){
// draw the flower based on random attributes shape and rotation angle, with size increase over time
size += 0.5;
if(shape==0){
squareFlower(20,20,size,[121, 173, 220,20]);
ellipseFlower(20,20,size-10,[121, 173, 230,50]);
}else if(shape==1){
ellipseFlower(20,20,size,[121, 173, 220,20]);
squareFlower(20,20,size-50,[121, 173, 230,50]);
}
}
//draw flower with squares
function squareFlower(x,y,size,fcolor){
//repeat drawing the square with the rotation of angle until the 360 degree is full
for(let i =0; i<(360/angle); i++){
rotate(angle);
stroke(fcolor[0], fcolor[1],fcolor[2]);
fill(fcolor[0], fcolor[1],fcolor[2],fcolor[3]);
rect(x,y,size);
}
}
//draw flower with ellipse
function ellipseFlower(x,y,size,fcolor){
//repeat drawing the circle with the rotation of angle until the 360 degree is full
for(let i=0; i<(360/(angle+20)); i++){
rotate(angle+20);
fill(fcolor[0], fcolor[1],fcolor[2],fcolor[3]);
// noFill();
stroke(fcolor[0], fcolor[1],fcolor[2]);
ellipse(x,y,size,size+10);
}
}
// change the attributes of flower each time mouse is released
function mouseReleased(){
shape = random([0,1]);
size = 60 + int(random(50))
angle = int(random(30)) + 30;
}