color fSfondo, fPrimo, fSecondo, sPrimo, sSecondo, cLettere;
int dx, dy; // dimensioni applicazione
int N; // numero lati
float CCx, CCy, Ax, Bx, // centro ed estremi diametro
P0x, P0y, // vertice iniziale
P1x, P1y, P2x, P2y, // lato
Lx, Ly, // lettere
alfa, delta, delta2, // angoli
CCr, CCd; // raggi e diametro
PFont fontLettere; // font per vertici
void setup()
{
size(500, 500);
ellipseMode(CENTER_RADIUS);
smooth();
dx=width;
dy=height;
CCx=dx/2;
CCy=dy/2;
CCr=dy*0.45;
CCd=2*CCr;
Ax=CCx-CCr;
Bx=CCx+CCr;
P0x=CCx;
P0y=CCy-CCr;
fontLettere=loadFont("C16.vlw");
textFont(fontLettere);
fSfondo =color(255, 255, 255);
fPrimo =color(0, 0, 0);
sPrimo =color(0);
fSecondo=color(0, 255, 0, 50);
sSecondo=color(0, 255, 0);
cLettere=color(0, 0, 255);
}
void draw()
{
aggiorna();
background(fSfondo); smooth();
strokeWeight(1);
stroke(sSecondo);
fill(fSfondo);
ellipse(CCx, CCy, CCr, CCr);
P1x=P0x;
P1y=P0y;
alfa=HALF_PI;
for(int i=1; i<=N; i++)
{
alfa+=delta2;
P2x=CCx+CCr*cos(alfa);
P2y=CCy-CCr*sin(alfa);
strokeWeight(1);
stroke(sSecondo);
fill(fSecondo);
triangle(P1x, P1y, P2x, P2y, CCx, CCy);
strokeWeight(2);
stroke(sPrimo);
line(P1x, P1y, P2x, P2y);
stroke(cLettere);
fill(cLettere);
ellipse(P1x, P1y, 2, 2);
P1x=P2x;
P1y=P2y;
}
ellipse(P0x, P0y, 2, 2);
text("#Punte = "+N, 10, dy-10);
}
void aggiorna()
{
float x=constrain(mouseX, Ax, Bx)-Ax;
N=(int)(15*(x/CCd))+2; N=2*N+1;
delta=TWO_PI/N; delta2=2*delta;
}