注意:正如代码所示,String[] 圈子没有用...
在这里,我以处理方式写了一个示例......希望它有所帮助:
//an array of your class type
Flower[] flowers = new Flower [3];
// one alone..
Flower atMouse = new Flower(0, 0);
void setup() {
size(400, 400);
// initialize objects
for (int i=0; i < flowers.length;i++)
{
int pos = i+1;
flowers[i] = new Flower (pos*100, pos*100);
}
smooth();
background(255);
}
void draw() {
background(255);
for (int i=0; i < flowers.length;i++)
{
flowers[i].display();
}
atMouse.display(mouseX, mouseY);
}
class Flower {
//class member variables
float posX;
float posY;
int c1 = 0;
int c2 = -40;
int c3 = 50;
int c4 = 50;
// a constructor
Flower(float _posX, float _posY)
{
//just pass vars
posX = _posX;
posY = _posY;
}
void display()
{
noStroke();
pushMatrix();
translate(posX, posY);
fill(#c6ff89); // green
for (int i = 0; i < 5; i++) {
ellipse(c1, c2, c3, c4);
rotate(radians(72));
}
popMatrix();
// centre circle
fill(#fff9bb); // light yellow
ellipse(posX, posY, 50, 50);
}
//an overloaded version to keep pos updating...
void display(float px, float py)
{
noStroke();
pushMatrix();
translate(px, py); // here use px instead...
fill(#c6ff89); // green
for (int i = 0; i < 5; i++) {
ellipse(c1, c2, c3, c4);
rotate(radians(72));
}
popMatrix();
// centre circle
fill(#fff9bb); // light yellow
ellipse(px, py, 50, 50);//also here
}
}//eofcl