you need to check the distance to y that actually should be x...
but you cant cause you create another x withing your class so i renamed it, and also made it flexible. that you can change the circlewidth...
Code:ArrayList balls;
int numBalls = 100;
int currentBall = 0;
int ballWidth = 25;
float linex = 0.0;
boolean ball = false;
boolean start = false;
PFont font;
void setup(){
size(500,550);
smooth();
balls = new ArrayList();
font = createFont("GillSans-48.vlw",42);
textFont(font);
}
void draw(){
background(0);
stroke(247,15,15,200);
strokeWeight(8);
if(start == true){
linex = linex + 2.0;
line(linex,0.0,linex,500);
if(linex>=500){
linex=0;
}
}
stroke(255);
strokeWeight(4);
line(0,100,500,100);
line(0,200,500,200);
line(0,300,500,300);
line(0,400,500,400);
fill(250,25,25);
noStroke();
rect(0,500,500,500);
if((keyPressed == true) && (key == 's')){
start = true;
}
fill(255);
text("Press 's' to start",10,545);
for(int i = balls.size()-1; i>=0;i--){
Ball ball = (Ball) balls.get(i);
ball.display();
}
}
void mousePressed(){
ball =true;
balls.add(new Ball(mouseX, mouseY,ballWidth));
}
class Ball{
float x,y,w;
Ball(float tempX, float tempY, float tempW){
x = tempX;
y = tempY;
w = tempW;
}
void display(){
fill(255);
noStroke();
if(dist(x,0,linex,0)<=ballWidth/2)fill(255,0,0);
if(dist(x,0,linex,0)>=ballWidth/2)fill(255);
ellipse(x,y,w,w);
}
}