Animating Multiple Objects
If you want to animate two objects, you need variables for each of them.
int x1=0;
int x2=500;
void setup()
{
size(500,300);
}
void draw()
{
x1=x1+2;
if ( x1 > 500)
{
x1 = 0;
}
x2=x2 - 3;
if (x2 < 0)
{
x2=500;
}
background(128);
fill(255);
ellipse(x,50,40,40);
fill(0);
ellipse(x2,150,40,40);
}
Whenever you want to add another object, you need another variable and the code to manipulate it.
int x1=0;
int x2=500;
float x3=1; // floating-point so we can use fractional multiplication
void setup()
{
size(500,300);
}
void draw()
{
x1=x1+2;
if ( x1 > 500)
{
x1 = 0;
}
x2=x2 - 3;
if (x2 < 0)
{
x2=500;
}
x3=x3*1.01;
if (x3 > 500)
{
x3=1;
}
background(128);
fill(255);
ellipse(x1,50,30,30);
fill(0);
ellipse(x2,150,30,30);
fill(255,0,0);
ellipse(x3,100,10,10);
}