// shooting upwards a number of balls of random colors // variation in initial speed for each int nofBalls=100; // wow: 100 ballsball // now we must have an array of each kind of variable for each float[] x = new float[nofBalls]; // use float for precise calculation float[] y = new float[nofBalls]; float[] speedx = new float[nofBalls]; float[] speedy = new float[nofBalls]; int[] c1 = new int[nofBalls]; int[] c2 = new int[nofBalls]; int[] c3 = new int[nofBalls];//float speedx=2, speedy=-60; // x and y component of the motion speed float fx = 0, fy = 3; // gravity vector bringing down ball int r = 2; // radius of ball//int c1=0, c2=0, c3=255; // ball color components; boolean fade = true; void setup() { size(600, 600); frameRate(30); noStroke(); smooth(); for (int j=0; j width ) { // assure subtle collision at sides speedx[j] = (-1)*speedx[j]; x[j] = width-r; } else if(x[j]-r < 0 ) { speedx[j] = (-1)*speedx[j]; x[j] = r; } if(y[j]+r > height ) { // hack below to let ball stay on ground speedy[j] = 0; speedx[j] = 0; y[j] = height-r; // shoot = false; // ball on earth, no need to redraw further //speedy = (-1)*speedy; //y = height-r; } else if(y[j]-r < 0 ) { speedy[j] = (-1)*speedy[j]; y[j] = r; } } } void drawCicle() { for (int j=0; j