The example you are referring to is programmed in an "object-oriented" manner, meaning the code for displaying a Spring object lives inside the Spring "class."
Code:
class Spring {
// all about a Spring
}
Since fill() uses a hard-coded value in the class, all Spring objects will always be colored with that same value, no matter how many Springs you make:
Code:
void draw()
{
if(over) {
fill(153);
} else {
fill(255);
}
ellipse(tempxpos, tempypos, size, size);
}
If you want to make Springs each with a different color, you need to introduce a color variable inside the class.
Code:
class Spring
{
color normColor;
color overColor;
// Constructor
Spring(float x, float y, int s, float d, float m,
float k_in, Spring[] others, int id,
color c1, color c2)
{
normColor = c1;
overColor = c2;
}
void draw()
{
if(over) {
fill(overColor);
} else {
fill(normColor);
}
ellipse(tempxpos, tempypos, size, size);
}
}
Then you can make two Spring objects with different colors:
Code:
springs[0] = new Spring( 70, 160, 20, 0.98, 8.0, 0.1, springs, 0, color(255), color(150));
springs[1] = new Spring(150, 110, 60, 0.95, 9.0, 0.1, springs, 1), color(255,0,0), color(0,0,255));
For more about how objects and classes work in Processing, check out:
http://itp.nyu.edu/icm/shiffman/week3/index.html