/** Press any key or click the mouse in the square to scatter cherry blossom petals */ Petals[] petals=new Petals[1]; //declare the petals array float gravity = 0.2; void setup() { size(600,600); smooth(); noStroke(); frameRate(30); petals[0] = new Petals(mouseX,mouseY); background(#28DB26); } void draw() { background(#28DB26); //clear background to simulate movement for (int i = 0; i < petals.length; i++){ petals[i].gravity(); petals[i].move(); petals[i].display(); } } void keyPressed(){ //adds random petals Petals q = new Petals(mouseX,mouseY); petals = (Petals[]) append(petals,q); } class Petals { // class variables (data) float x1, y1, x2, y2, x3, y3, x4, y4; float speed; //class contructor Petals(float tempX, float tempY){ x1 = tempX; y1 = tempY; x2 = tempX + random(-10,10); y2 = tempY + random(-10,10); x3 = tempX + random(-10,10); y3 = tempY + random(-10,10); x4 = tempX + random(-15,15); y4 = tempY + random(-15,15); speed = 0; } // class methods (functions) void gravity(){ speed = speed + gravity; } void move(){ //petals are pulled downwards by gravity y1 = y1 + speed; y2 = y2 + speed; y3 = y3 + speed; y4 = y4 + speed; //petals spread out randomly x1 = x1 + random(-5,5); x2 = x2 + random(-5,5); x3 = x3 + random(-5,5); x4 = x4 + random(-5,5); } void display(){ fill(#FF83B1); //pink triangle(x1,y1,x1+random(-15,15),y1+random(-15,15),x1+random(-15,15),y1+random(-15,15)); fill(#FFFFFF); //white triangle(x2,y2,x2+random(-15,15),y2+random(-15,15),x2+random(-20,20),y2+random(-15,15)); fill(#FF83B1); //pink triangle(x3,y3,x3+random(-15,15),y3+random(-15,15),x3+random(-20,20),y3+random(-15,15)); fill(#FCB5B5); //light pink triangle(x4,y4,x4+random(-15,15),y4+random(-20,20),x4+random(-20,20),y4+random(-15,15)); } }