Now, I have two methods to solve the overlapping issue.
The first method is using the PGraphics.
PGraphics pg2;
int numCircles = 18;
float r=400;
float kuan=200;
float chang=400;
void setup() {
fullScreen();
noLoop();
pg2 = createGraphics(width, height);
background(#82A584);
}
void draw() {
// draw the picture
pg2.beginDraw();
pg2.translate(width/2, height/2);
pg2.fill(#FA677D);
pg2.strokeWeight(6);
pg2.stroke(#D8A2AA);
for (int i = 0; i < numCircles; i++) {
pg2.rotate(TWO_PI/numCircles);
pg2.ellipse(0, r, kuan, chang);
}
pg2.endDraw();
// cut the picture
PImage img2 = pg2.get(width/2, 0, width, height);
// paste the picture
translate(width/2, height/2);
for (int i = 4; i>0; i-=1) {
scale(0.8);
image(img2, 0, -height/2);
rotate(PI);
image(img2, 0, -height/2);
}
line(-width*2,0,width*2,0);
line(0,-height*2,0,height*2);
save("zinnia_PGraphics.png");
}
The result is good, but the code itself is not a loop.
The second one is using the P3D.
int pedalNum = 18;
float r=400;
float kuan=400;
float chang=400;
void setup() {
fullScreen(P3D);
noLoop();
background(#82A584);
stroke(#D8A2AA);
strokeWeight(6);
fill(#FA677D);
}
void draw() {
translate(width/2, height/2, 0);
for (int i = 4; i>0; i--) {
scale(0.7);
translate(0,0,400);
for (int j = 0; j<pedalNum; j++) {
push();
rotateZ(TWO_PI/pedalNum*j);
rotateY(PI/3);
ellipse(0, -r, kuan, chang);
pop();
}
}
translate(0,0,200);
stroke(120);
line(-width,0,width,0);
line(0,-height,0,height);
save("zinnia_P3D.png");
}
The code is a correct loop, but pedals are
slanted. I don’t know the reason why the pedal is slanted and how to eliminate the slant. Can someone help to improve the code?