Processing Forum
void setup()
{
size(500, 500);
balls=new ball[1];
for (int i=0;i<balls.length;i++)
{
balls[i]=new ball();
}
}
void draw() {
background(0);
for (int i=0; i<1;i++)
{
ball[i].move();
ball[i].display();
}
}
class ball {
float x, y;
float speed;
color c;
float radius;
float gravity;
ball() {
radius=25;
x=250;
y=0;
speed=0;
gravity=0.1;
c=color(255);
ellipse(x, y, radius, radius);
}
void move()
{
y=y+speed;
speed=speed+gravity;
if (y>height) {
speed=speed*-0.95;
}
}
void display() {
fill(c);
noStroke();
ellipse(x, y, radius, radius);
}
}
}