void setup(){
size(500, 500);
}
void draw() {
background(255);
float ANG = PI/3;
// dessine les 6 lignes dans une boucle
stroke(255, 0, 100);
for (int i=0; i<6; i++) {
float x0 = width/4 +100*cos(i*ANG);
float y0 = height/4+100*sin(i*ANG);
float x1 = width/4 +100*cos((i+1)*ANG);
float y1 = height/4+100*sin((i+1)*ANG);
line(x0, y0, x1, y1);
}
// dessine un polygone point par point
stroke(100, 100, 255);
fill(200, 200, 255);
beginShape();
for (int i=0; i<6; i++) {
float x0 = 1*width/4 +100*cos(i*ANG);
float y0 = 3*height/4+100*sin(i*ANG);
vertex(x0, y0);
}
endShape(CLOSE);
|
// dessine un polygone triangle par triangle
stroke(100, 100, 255);
fill(200, 200, 255);
beginShape(TRIANGLE_FAN);
vertex(3*width/4, 1*height/4);
for (int i=0; i<7; i++) {
float x0 = 3*width/4 +100*cos(i*ANG);
float y0 = 1*height/4+100*sin(i*ANG);
vertex(x0, y0);
}
endShape(CLOSE);
// dessine une courbe point par point
stroke(100, 255, 200);
fill(200, 255, 200);
beginShape();
vertex(3*width/4 +100*cos(0), 3*height/4+100*sin(0));
for (int i=1; i<7; i++) {
float x0 = 3*width/4 +100*cos(i*ANG);
float y0 = 3*height/4+100*sin(i*ANG);
float dx = -50*sin(i*ANG);
float dy = 50*cos(i*ANG);
bezierVertex(x0+dx, y0+dy, x0-dx, y0-dy, x0, y0);
}
endShape(CLOSE);
}
|
un hexagone rose un polygone en 6 triangles un polygone rempli une forme en courbe

|