fhop
October 2, 2019, 10:26pm
1
Hi I would like to create a loop with red circles and blue polygons but when I do my loop only the circles in the center are red the rest are blue. I know I need to put the ellipse & polygon together in a loop but have no idea how, any help would be appreciated!
reference image attached
Thanks
void setup(){
size(500,500);
background(255);
//noStroke();
translate(width/2,height/2);
for (int j=0;j<8;j++){
fill(#35DEE3);
polygon(8,450.0);
scale(0.75);
}
}
void polygon(int sides, float radius){
float theta=0.0;
float x=0.0;
float y=0.0;
beginShape();
for (int i=0;i<sides;i++){
x=radius*cos(theta);
y=radius*sin(theta);
rotate(PI/7.0);
vertex(x,y);
theta=theta+2*PI/sides;
}
endShape(CLOSE);
float scaleFactor = 0.74;
float side = 830;
for (int i=0;i<5;i++){
ellipse(0,0,side,side);
fill(#E3354C);
side = side*scaleFactor;
} //end polygon
}
1 Like
kll
October 3, 2019, 1:57am
2
try to use
fill(color);
first.
void polygon(int sides, float radius) {
float theta=0.0;
float x=0.0;
float y=0.0;
beginShape();
fill(200,0,200);
for (int i=0; i<sides; i++) {
x=radius*cos(theta);
y=radius*sin(theta);
rotate(PI/7.0);
vertex(x, y);
theta=theta+2*PI/sides;
}
endShape(CLOSE);
float scaleFactor = 0.74;
float side = 830;
for (int i=0; i<5; i++) {
fill(0,0,200);
ellipse(0, 0, side, side);
//fill(#E3354C);
side = side*scaleFactor;
} //end polygon
}
please repair your code posting above,
using the
</> Preformatted text
button from the editor menu
2 Likes
fhop
October 4, 2019, 9:59am
3
Thanks for the response!
When I put that into my code all i can see is circles no polygons anymore?
void setup(){
size(500,500);
background(255);
//noStroke();
translate(width/2,height/2);
for (int j=0;j<8;j++)
fill(#35DEE3);
polygon(8,450.0);}
void polygon(int sides, float radius) {
float theta=0.0;
float x=0.0;
float y=0.0;
beginShape();
fill(200,0,200);
for (int i=0; i<sides; i++) {
x=radius*cos(theta);
y=radius*sin(theta);
rotate(PI/7.0);
vertex(x, y);
theta=theta+2*PI/sides;
}
endShape(CLOSE);
float scaleFactor = 0.74;
float side = 830;
for (int i=0; i<5; i++) {
fill(0,0,200);
ellipse(0, 0, side, side);
//fill(#E3354C);
side = side*scaleFactor;
}
}
kll
October 4, 2019, 10:27am
4
hm
anyhow i just added fill(color)
in front of
and
2 Likes
fhop
October 6, 2019, 8:33am
5
was missing a set of curly brackets. thanks so much!!
1 Like