// shooting upwards a number of balls // damping when touching the ground // friction on ground int nofBalls=100; 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 force vector bringing down ball int r = 2; // radius of ball float dampx = 0.98; // damping factor for bouncing back float dampy = 0.8; boolean damping = false; 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 ) { // bouncing speedy[j] = (-1)*speedy[j]*dampy; speedx[j] = speedx[j]*dampx; y[j] = height-r; } else if(y[j]-r < 0 ) { speedy[j] = (-1)*speedy[j]; y[j] = r; } } } void drawCicle() { for (int j=0; j