// draw polygons uisng shapes...so they are fillable
void setup() { // all sketch setup goes here size(400, 400); smooth(); background(255); } // setup()
void draw() { } // draw()
void mousePressed() { fill(random(255), random(255), random(255), random(255)); drawPolygon(mouseX, mouseY, random(20, 80), int(random(3, 12))); } // mousePressed()
void drawPolygon(float cx, float cy, float sz, int nSides) { // draw a hexagon centered at cx, cy float x1, y1, x2, y2; float radius = sz/2; float theta = 0.0; float delta = 360.0/nSides;
point(cx, cy); // ellipse(cx, cy, sz, sz);
// compute x1, y1
beginShape(); for (int i = 0; i < nSides; i++) { x1 = cx + radius * cos(radians(theta)); y1 = cy - radius * sin(radians(theta)); vertex(x1, y1); theta = theta + delta; } endShape(CLOSE); } // drawPolygon