We are about to switch to a new forum software. Until then we have removed the registration on this forum.
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???
Answers
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 {
} void display(){ fill(255); noStroke(); ellipse(x,y,a,a);} }
Edit your post
Format your code better
Not bad at all!
Now add the things I told you
how ??
Look at the examples...
https://processing.org/examples/bouncybubbles.html
Here see function move()
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(...)
sayradius = radius - 0.3;
or even smallerWhen
radius <= 0
you could mark the ball as dead using a boolean variableisDead = true;
inside the classclass 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);
} } void show() { stroke(255); ellipse( x, y, 20, 20); radius = radius - 0.05; if(radius <= 0) { bDead =true; println("dead"); } } }
its not making the balls smaller . why?
you still don't use radius in ellipse()......
please don't post duplicates.
https://forum.processing.org/two/discussion/26908/how-to-change-balls-that-are-falling-from-big-to-a-smaller-size-gradually