/* Homework #3 - ICM Michael Chladil 2006-09-26 Description: When the mouse is pressed, a blue water droplet is released and falls to the ground. Up to twenty droplets can be released. This program does not simulate evaporation. When the twenty droplets are released, no more are available. */ class Droplet { int x; int y; int dWidth; int dHeight; int speed; Droplet (int initX, int initY, int initdWidth, int initdHeight) { x = initX; y = initY; dWidth = initdWidth; dHeight = initdHeight; speed = 2; } void display () { ellipse (x, y, dWidth, dHeight); } void move () { if (y < (height - dHeight)) { y += speed; speed++; // Accelerate the water droplet as it approaches the ground } else // flatten out the droplet when it hits the ground { if (dHeight > 0) dHeight -= 3; } display (); } } int MAX_DROPLETS; Droplet []Droplets; int dropletCount = 0; void setup () { smooth (); framerate (30); size (600, 600); fill (#1E77A5); stroke (#1E77A5); MAX_DROPLETS = 20; Droplets = new Droplet [MAX_DROPLETS]; } void draw () { int i = 0; background (0,0,0); for (i = 0; i < dropletCount; i++) { Droplets[i].move(); } } void mousePressed() { if (dropletCount < MAX_DROPLETS) { Droplets[dropletCount] = new Droplet (mouseX, mouseY, int (random (20)) + 20, int (random (20)) + 20); Droplets[dropletCount].display(); dropletCount++; } }