class Drop {//create a object
PVector pos;//positon of the drop
PVector vel;//velocity of the drop
color c;//colour of the drop
float s; //size
Drop (PVector _pos, color _c, float _s){//function--"constructor"-makes the drop
pos = _pos;//take the incoming information and store it
c = _c;
s = _s;
vel = new PVector (0,0);
}
void render(){
fill(0,80,200,100);//fill the drop
noStroke();
ellipse(pos.x,pos.y,s,s);//draw the drop on the screen
//draw a drop
}
void move(){//make drops move
pos.add(vel);//add the velocity vector to our position
PVector gravity = new PVector(0, 0.1);//create a new vector--gravity
vel.add(gravity);//add gravity vector
}
}
ArrayList Drops = new ArrayList(); //a bucket to store the drops
Drop D;// the Drop in the second tap
boolean drawdrop = true;//set up the boolean of the drawdrop
PImage faucet; //stores image
void setup() {
size(580,640);//set the size of the frame
background(238,238,238);//set the colour of the background
faucet = loadImage("faucet.jpg");//load the image in the data
}
void draw() {
image(faucet,40,40,520,600); //drow the image
for(int i=0;i<Drops.size();i++) { //iterate over our ArrayList
Drop D = (Drop)Drops.get(i); //get one Drop out
D.move(); //move the drop
D.render(); //draw the drop
}
if (mousePressed == true) {
drawdrop=false;//if the mouse is pressed, stop drawing the drop
}
else {
drawdrop= true;//otherwise, keep drawing the drops
}
if (frameCount%20 == 0 && drawdrop==true) {//set the drops keep moving
Drop D = new Drop(new PVector(70,235),color(0,0,0),40);//set up the PVector of the new drop
Drops.add(D);//add new drops
}
}
void keyPressed(){ //this runs when a key is pressed
save("wallpaper.jpg"); // save a file
}
Using class function to store a drop and using array lists to make more drops move