Quote:so, i would continuously re-draw the spheres and manipulate the positions?
exactly.
Actually, you want an array of spheres, but Processing doesn't have built-in sphere objects : only a graphic sphere() method which draws a sphere at a certain position, that's all.
Start with a custom Sphere class describing what a sphere is, from your point of view, and then simply put them in a array :
Code:class Sphere {
// position, radius and color
float x, y, z;
float r;
color c;
// simple constructor
public Sphere(float x, float y, float z, float r, color c) {
this.x = x;
this.y = y;
this.z = z;
this.r = r;
this.c = c;
}
// display the sphere on the screen
void display() {
fill(c);
pushMatrix();
translate(x, y, z);
sphere(r);
popMatrix();
}
}
Code:Sphere[] arrayOfSpheres;
void setup() {
// set up the array
arrayOfSpheres = new Sphere[10];
arrayOfSpheres[0] = new Sphere(0, 0, 0, 5, color(100));
// ...
arrayOfSpheres[9] = new Sphere(10, 0, 0, 7, color(50));
}
void draw() {
// clear the screen
background(255);
// display the spheres
for (int i = 0; i < arrayOfSpheres.length; i++) {
arrayOfSpheres[i].display();
}
}