ArrayList balls; final int AMOUNT = 8; final float G = 0.3; void setup() { size(500,500); background(255); smooth(); noStroke(); ellipseMode(CORNER); colorMode(HSB,100); balls = new ArrayList(); for(int i=0;i<=AMOUNT;i++){ balls.add(new Ball(0,0,i,0,i*10,i*10)); } } void draw() { background(100); for(int i=0;i<=AMOUNT;i++){ Ball b = (Ball)balls.get(i); b.update(); b.draw_ball(); } } class Ball { float xPos,yPos,Vx,Vy,rSize,gravity; int bColor; Ball(float x, float y,float vx, float vy, float size ,int ball_color ){ xPos = x; yPos = y; Vx = vx; Vy = vy; rSize = size; bColor = ball_color; float r = random(2,5); gravity = G*r; } void draw_ball(){ xPos += Vx; if(yPos+rSize>height-0.05) yPos = height-rSize; else yPos += Vy/2; fill(bColor,20,99,80); ellipse(xPos,yPos,rSize,rSize); } void update(){ if(xPos+rSize >width){ xPos=2*(width-rSize)-xPos; Vx = -0.9*Vx; } else if(xPos<0){ xPos = abs(xPos); Vx = -0.95*Vx; } if(yPos+rSize>height){ yPos = 2*(height-rSize)-yPos; Vy = -0.9*Vy; } Vy +=gravity; } }