We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I woulkd like the triangle fan to rotate. Of course I tried rotate(), but i couldn't get it working properly.
The Code:
Kranz stKranz;
int radian = 300;
int numbeams = 36;
void setup() {//setup
smooth();
size(600, 600);
colorMode(RGB,360);
background(360);
stroke(360);
stKranz = new Kranz ();
}
void draw() {
//background(360);
stKranz.display();
//resetMatrix();
}
The Class Tab Code:
class Kranz{
float beams = 360/numbeams;
float r = 0;
Kranz(){
beginShape(TRIANGLE_FAN);
vertex(width/2, height/2); //zentriert
for (float angle = 0; angle <= 360; angle+=beams) {
float vx = width/2 + cos(radians(angle))*radian;
float vy = width/2 + sin(radians(angle))*radian;
fill(angle, 0, 0);
vertex(vx, vy);
}
endShape();
}
void display(){
}
}
Answers
actually you could make the shape in the constructor Kranz() and
store it in a PShape variable
and use it in
display()
explanation
the point is that the rotation takes place around the origin (0,0)
Hence, you need to draw the fan over 0,0
it extends from -radius (minus radius) to plus radius so its center is exactly on the origin