I have a very simple sketch (-just some balls flying and bouncing of the screen edges-), but when I run it, it does not seem to get to a smooth motion. Every now and then (~once in 5-10sec) it seems to "jitter" a bit.
Do others see the same effect when running my code, or is it due to processor speed? I run processing on an Intel Core2 Duo P8600 (2.4 Ghz) with 4 GB RAM on a 64-bit Vista and wouldn't have expected speed problems here.
Any comments? Something obviouse I can't see in the code?
Code:
ArrayList balls;
int nrBalls=4;
ball B;
void setup()
{
frameRate(60);
size(800,600);
smooth();
balls = new ArrayList();
for (int i=0;i<nrBalls;i++)
{
B= new ball(random(0,width),random(0,height));
B.speed = new PVector(4,3);
balls.add(B);
}
stroke(255,255,255,150);
}
void draw()
{
background(0);
for (int i=0;i<balls.size();i++)
{
B = (ball) balls.get(i);
strokeWeight(B.mass*2);
point(B.pos.x,B.pos.y);
// move ball
B.pos.add(B.speed);
constrain(B.pos.x,B.mass,width-B.mass);
constrain(B.pos.y,B.mass,height-B.mass);
// check boarder
if (B.pos.x<=B.mass) B.speed.x=abs(B.speed.x);
if (B.pos.x>=width-B.mass) B.speed.x=abs(B.speed.x)*(-1);
if (B.pos.y<=B.mass) B.speed.y=abs(B.speed.y);
if (B.pos.y>=height-B.mass) B.speed.y=abs(B.speed.y)*(-1);
}
}
class ball
{
PVector speed;
PVector pos;
float mass;
ball(float x, float y)
{mass=int (random(10,50));speed=new PVector(0,0);pos=new PVector(x,y);}
}