xxxxxxxxxx
//Variables
int numCircs = 300;
//Speed
float [] speedx = new float [numCircs];
float [] speedy = new float [numCircs];
//Button
int[] rectX = new int [100];
int[]rectY = new int [100];
int[]rectW = new int [100];
int[]rectH = new int [100];
//Ball
int[]ballW = new int [100];
int[]ballH = new int [100];
// Location
float [] ballXpos = new float [numCircs]; //# of balls I want
float [] ballYpos = new float [numCircs]; //# of balls I want
// ball touched the button?
boolean button = false;
void setup () {
size (400, 400);
for(int i = 0; i < 100; i++){
speedx[i]=(int)random(100);
}
// either i++ or i = i + 1never both!
for (int i = 0; i < ballYpos.length; i = i+1) {
speedy[i]=(int)random(100);
}
}
void draw () {
background(0,0,0);
strokeWeight(10);
frameRate(1000);
for (int i = 0; i < width; i++) {
float r = random(255);
stroke(r);
line(i, 0, i, height);//help from processing.org
if (button == true) {
rect (width/2, height/2, 300,300);
} else {
// if no touch stays same
background(255,0,0);
}
for (int c = 0; c < numCircs; c = c+1) {
fill (255, 0, 0);
ellipse (ballXpos[c], ballYpos[c], 30, 30);
ballYpos[c] = ballYpos[c] + speedy[c];
ballXpos[c] = ballXpos[c] + speedx[c];
if ( (ballXpos[c] > width) || (ballXpos[c] < 10) ) {
speedx[c] = speedx[c] * -1;
}
// is the ball touching the top or bottom?
if ( (ballYpos[c] > height) || (ballYpos[c] < 10) ) {
speedy[c] = speedy[c] * -1;
}
}
}
}