//import processing.opengl.*; //use opengl for faster rendering int unit = 40; int num; Foo[] mods; int size = 400; boolean bg; void setup() { //size(size, size, OPENGL); //use opengl for faster rendering size(400, 400); // to make an applet happy //noStroke(); frameRate(50); smooth(); num = 50; mods = new Foo[num]; reset(); } void reset() { for(int i=0; itolerance || abs(vel[idx])>tolerance; // // alive = (size-pos[1])>30;// && abs(acc[idx])>gravity; // idx++; // } return alive; } float friction = .9998; float gravity = .001; float elastic = .7; int max = size; void addAcceleratedSpeed() { for( int i = 0; i < pos.length; i++) { vel[i] *=friction; float tmpVel = vel[i] + acc[i]; float tmp = pos[i] + tmpVel; boolean collision = false; if (tmp>= max || tmp<0) collision = true; if (collision) { vel[i] *= -elastic ; acc[i] *=elastic; tmpVel = vel[i] + acc[i]; tmp = pos[i] + tmpVel; } vel[i] = tmpVel; pos[i] = tmp; } } void addSpeed(float[] pos, float[] vel, int max) { for( int i = 0; i < pos.length; i++) { float tmp = pos[i] + vel[i]; if (tmp> max) { vel[i] = -dRand(); pos[i] += vel[i]; } else if (tmp<0) { vel[i] = dRand(); pos[i] += vel[i]; } else { pos[i] = tmp; } } } void move() { } void draw() { ellipseMode(CENTER); float x = mass, y=mass; if (pos[0] + mass>size) { x = pos[0]-size; } else if (pos[0] - mass<0) { x = 0-pos[0]; } if (pos[1] + mass>size) { y = pos[1]-size; } else if (pos[1] - mass<0) { y = 0-pos[1]; } ellipse(pos[0], pos[1], x , y); fill(col[0], col[1], col[2]); } }