We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hey coders,
i am trying to draw a triangle-fan, but anyway it is not displaying. Could someone have a look?
Many thanks!
int segmentCount = 6;
int radius = width/2;
float angleStep = 360/segmentCount;
color black = #222222;
color white = #eeeeee;
color red = #E14C45;
void setup() {
size(300, 300);
}
void draw() {
background(white);
fill(red);
stroke(black);
beginShape(TRIANGLE_FAN);
vertex(width/2, height/2);
for (float angle=0; angle<=360; angle = angle + angleStep) {
float vx = width/2 + cos(radians(angle))*radius;
float vy = height/2 + sin(radians(angle))*radius;
vertex(vx, vy);
}
endShape();
}
This is what i've expected.
Answers
You're using width on line 2 before setting the width. Just assign the value o radius on setup.
Thank you !!!