See below.
Particle [] pickles = new Particle [100];
void setup () {
size (500, 500);
smooth ();
for (int i=0; i<pickles.length; i++) {
pickles [i] = new Particle ();
}
}
void draw () {
background (0); //clear the background
for (int i=0; i<pickles.length; i++) {
pickles[i].update();
}
}
class Particle {
float x;
float y;
float velX ; // speed or velocity
float velY;
Particle () {
//x and y position to be in middle of screen
x = width/2;
y = height/2;
velX = random (-10, 10);
velY = random (-10, 10);
}
void update () {
x+=velX;
y+=velY;
// Stop them from going off the left side.
if( x < 5 ){
x = 5;
velY = 0;
}
// Stop them from going off the right side.
if( x > width - 5 ){
x = width - 5;
velY = 0;
}
// I will leave these two up to you!
// TODO: Stop them from going out the top.
// TODO: Stop them from going out the bottom.
fill (255);
ellipse (x, y, 10, 10);
}
}