1. Move your mouse quickly, then slower and slower... 2. Press 'b' for a different background 3. Press 'm' for some more random flowers 4. Press 'c' to clear
xxxxxxxxxx
//var s = 0;
var color0 = "powderblue";
var color1 = "lightseagreen";
var color2 = "honeydew";
var color3 = "lightsalmon";
var color4 = "palevioletred";
function setup() {
createCanvas(windowWidth, windowHeight);
background("black");
frameRate(9);
}
function drawFlower(x, y){ //rand (req. 3)
var choosecolor = floor(random(5));
var fillcolor = floor(random(1));
if(choosecolor == 0) stroke(color0);
if(choosecolor == 1) stroke(color1);
if(choosecolor == 2) stroke(color2);
if(choosecolor == 3) stroke(color3);
if(choosecolor == 4) stroke(color4);
if(fillcolor == 0) fill(random(255), random(255), random(255), 50);
translate(x, y); //inspired by https://p5js.org/examples/hello-p5-simple-shapes.html
for (let i=0; i<10; i++) {
ellipse(0, 50, 20, 80);
rotate(PI/5);
/*rotate(radians(s)); //I tried to make the flowers spin but failed :)
scale(0.25);
ellipse(0, 125, 70, 150);
ellipse(0, 200, 120, 200);
s++;*/
}
}
function draw() { //mouse reaction (req. 1)
var speed = dist(mouseX, mouseY, pmouseX, pmouseY); //hypotenuse
if(key=='b'){ //new background
rect(0,0,width,height);
}
strokeWeight(speed*0.7); //make the flowers fast and fat
line(pmouseX, pmouseY, mouseX, mouseY);
drawFlower(mouseX + random(-100,100), mouseY + random(-100,100));
}
function keyTyped(){
if(key=='c'){ //clear function (req. 2)
background("black");
}
if(key=='m'){ //add some more random flowers!
drawFlower(random(-500,500), random(-500,500));
}
}