#### Howdy, Stranger!

We are about to switch to a new forum software. Until then we have removed the registration on this forum.

# falling balls

edited March 2018

so i need to do a project. i need to make balls fall like rain and every ball needs to have a different color. And when they tuch the ground they need to bounce off and then faid of . Can anybody help me???

• the balls have to be big at first and when they fall get smaller

• Sure

Make a class Ball and an array of it (before setup ())

See tutorial objects

Then fill the array in setup

Move and display array in draw

See examples on movement and gravity

For fade see opacity in command fill

Then show your entire code and tell us what you have problems with

Chrisir

• ArrayList balls; float a;

void setup(){ size(600,600); balls = new ArrayList(); } void draw() { background(230,230,250); balls.add(new Ball()); for (Ball balls:balls){ balls.fall(); balls.display(); } } class Ball {

`````` float x=random(width);
float y=random(-200,100);
float yspeed=random(3,4);
float a=random(40);

void fall(){
if (y<height) {
y+=yspeed;
}
``````

} void display(){ fill(255); noStroke(); ellipse(x,y,a,a);} }

Now add the things I told you

• how ??

• Look at the examples...

• how do you make it become smaller and smaller ?

• You can have a fade or radius variable inside the class

Now use the radius variable with ellipse() command

Let’s make it a float variable radius = 7 : `float radius = 7;`

After `ellipse(...)` say `radius = radius - 0.3;` or even smaller

When `radius <= 0` you could mark the ball as dead using a boolean variable `isDead = true;` inside the class

• class Drop { float x = random(width); float y = random(-500, -50); float yspeed = random (1, 6); float radius = 7; boolean bDead; void fall() { y = y + yspeed; //yspeed = yspeed + 0.05;

if(y > height) { y = random(-200.-100);