Assignment 1

PImage img;
float theta;

Rain r1;

int numDrops = 50;
Rain[] drops = new Rain[numDrops]; // Declare and create the array

void setup() {
size(1000, 780);
img = loadImage(“bet.jpeg”);
smooth();
noStroke();
//Loop through array to create each object
for (int i = 0; i < drops.length; i++) {

drops[i] = new Rain(); // Create each object
r1 = new Rain();
}
}

void draw() {
image(img, 0, 0);
frameRate(30);
stroke(#1F8623);
// angle 0 to 90 degrees based on the mouse position
float a = (mouseX / (float) width) * 90f;
// Convert it to radians
theta = radians(a);
// Start tree bottom of the screen
translate(width/2,height);
// Draw a line 120 pixels
line(0,0,0,-120);
// Move to the end of that line
translate(0,-120);

branch(120);
r1.fall();

fill(255,80);
//Loop through array to use objects.
for (int i = 0; i < drops.length; i++) {
drops[i].fall();

}
}

class Rain {
float r = random(-600, 600);
float y = random(-height);

void fall() {
y = y + 7;
fill(#76A4D1);
ellipse(r, y, 10, 10);

if(y>height){
r = random(-600, 600);
y = random(-600, 600);
}
}
}

void branch(float h) {
// Each branch 2/3rds the size of the previous one
h *= 0.66;

if (h > 2) {
pushMatrix();
rotate(theta); // Rotate by theta
line(0, 0, 0, -h); // Draw branch
translate(0, -h); // the end of the branch
branch(h);
popMatrix();

// left side
pushMatrix();
rotate(-theta);
line(0, 0, 0, -h);
translate(0, -h);
branch(h);
popMatrix();
}
}