Poligoni regolari

color fSfondo, fPrimo, fSecondo,
               sPrimo, sSecondo,
      cLettere;   
int   dx,        // dimensioni applicazione
      dy; 
float CCx, CCy,  // ordinate            
      Ax, Bx,
      P0x, P0y,
      P1x, P1y,
      P2x, P2y,
      Lx, Ly,
      alfa, delta,
      CCr,
      CCr2,
      CCd;

int   N;
PFont fontLettere;

void setup()
{
   size(500, 500); ellipseMode(CENTER_RADIUS); smooth();

   dx=width;       dy=height;
   CCx=dx/2;       CCy=dy/2;  CCr=dy*0.45;
                              CCr2=dy*0.45;
                              CCd=2*CCr;
   Ax=CCx-CCr;
   Bx=CCx+CCr;
   P0x=CCx;
   P0y=CCy-CCr;
   alfa=HALF_PI;
   delta=TWO_PI/3;
   N=3;
   
   fontLettere = loadFont("C16.vlw");
   textFont(fontLettere);
   
   cLettere=color(0, 0, 255);       
    fSfondo=color(255, 255, 255);
     fPrimo=color(0, 0, 0);              sPrimo=color(0);
   fSecondo=color(0, 255, 0, 50);   sSecondo=color(0, 255, 0);  
   
   noLoop();
}

void mouseMoved()
{
  redraw();
}


void draw()
{  
  aggiorna();
  
  background(fSfondo); smooth();   strokeWeight(1);               
  
  stroke(sSecondo);
  fill(fSfondo);           ellipse(CCx, CCy, CCr, CCr);
  
  
  for(int i=1; i<=N; i++)
  {
      smooth();    strokeWeight(1);               
      alfa+=delta;
      P2x=CCx+CCr*cos(alfa);
      P2y=CCy-CCr*sin(alfa);
      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);
  
  stroke(cLettere);
  fill(cLettere);       text("#Lati = "+N, 10, dy-10);
}
void aggiorna()
{
   alfa=HALF_PI;
  
   P1x=P0x;  P1y=P0y;
   
   float x=constrain(mouseX, Ax, Bx)-Ax; 
   
   N=(int)(33*(x/CCd)+3);   
   delta=TWO_PI/N;
}