Ball[] balls = new Ball[1]; float colVar_r = 0; float colVar_g = 0; float colVar_b = 0; float gravity = 0.1; float w; void setup(){ size(400, 300); smooth(); frameRate(30); //initialise balls balls[0] = new Ball(50,0,16); } void draw(){ background(209); //move and display stripes for(int i = 0; i < balls.length; i++){ balls[i].gravity(); balls[i].move(); balls[i].display(); } } void mousePressed(){ //new ball object Ball b = new Ball(mouseX, mouseY, w); //append to array balls = (Ball[]) append(balls,b); } class Ball{ float x; float y; float speed; float w; Ball(float tempX, float tempY, float tempW){ x = tempX; y = tempY; //w = tempW; speed = 0; w = random(10,40); } void gravity(){ speed = speed + gravity; } void move(){ y = y + speed; //if ball reaches bottom, reverse speed if(y > height){ speed = speed * -0.95; y = height; } } //draw stripe void display(){ //show circle colVar_r = random(255); colVar_g = random(255); colVar_b = random(255); fill(colVar_r,colVar_g,colVar_b); noStroke(); ellipse(x,y,w,w); } }