Rain Splash

so im new to coding and so i went along with the "purple rain" video by Daniel Shiffman, and i wanted to add a splash to it. so i made a "sidewalk" type thing and then pretty much used the same code for the rain drop for the splash, but i need to make it so that when a raindrop hits a certain point it starts the splash animation. can i get some help with that?

here is my code.

Splash[] splash = new Splash[100]; Drop[] drops = new Drop[500];

void setup() { size(640, 320); for (int i = 0; i < drops.length; i++) { drops[i] = new Drop(); } for (int i = 0; i < splash.length; i++) { splash[i] = new Splash(); } }

void draw() { background(230, 230, 250); rect(0,300,640,320); fill(96,70,135); for (int i = 0; i < drops.length; i++) { drops[i].fall(); drops[i].show(); } for (int i = 0; i < splash.length; i++) { splash[i].fall(); splash[i].show(); }

 }

}

class Drop { float x = random(width) ; float y = random(-500,-50); float z = random(0,20); float len = map(z,0,20,10,20); float yspeed = map(z,0,20,4,10);

void fall() { y =y + yspeed; float grav = map(z,0,20,0,0.2); yspeed = yspeed + grav;

 if (y > 300) {
    y = random(-200,-100);
    yspeed = map(z,0,20,4,10);

} }

void show() {

 float thick = map(z,0,20,1,3);
 strokeWeight(thick);
 line(x,y,x,y+10);
 stroke(138, 43, 226);

}

}

class Splash { float x = random(width) ; float y = random(200,150); float z = random(0,20); float len = map(z,0,20,10,20); float yspeed = map(z,0,20,4,10);

void fall() { y =y + yspeed;

 if (y > 300) {
    y = random(270,299);
    yspeed = map(z,0,20,4,10);

} }

void show() {

 float thick = map(z,0,20,1,3);
 strokeWeight(thick);
 line(x,y,x,y+10);
 stroke(138, 43, 226);

}

}

Tagged:

Answers

  • In the class drop you say if <300

    here you need to start the splash

    It starts at the pos of the drop (before its y gets resetted with random)

    so say .... new splash...

    then splash[index] .x =x; // copies the drop x value to the splash

    Same for y.

    Maybe you want 3-6 drops make your splash. Use a for loop

    Anyway. The problem I see that for the splash it is easier to use an ArrayList because otherwise it's hard to know which slot/ index to use in the splash array

Sign In or Register to comment.