/* * Regular Polygon implementation modeled after that on page 92 of Greenberg,Xu,Kumar text. * * Sketch by Michael Goldwasser */ void setup() { size(600,600); background(255); strokeWeight(2); // place origin at center of canvas translate(0.5*width, 0.5*height); // temporarily rotate coordinates to align stop sign pushMatrix(); rotate(0.125*PI); fill(255, 0, 0); regularPolygon(8, 0.4*width); popMatrix(); // undo effect of the rotation // at this point, translation still applies fill(255); textAlign(CENTER, CENTER); // not quite perfect, but close textSize(0.25 * width); text("STOP", 0, 0); // centered at translated origin } void draw() { } /** * Draws a regularly polygon having sideCount sides and * indicated radius, centered around the origin and with * first vertex aligned right of center. */ void regularPolygon(int sideCount, float radius) { float theta = 0.0; beginShape(); for (int i=0; i < sideCount; i++) { float x = radius * cos(theta); float y = radius * sin(theta); vertex(x,y); theta += TWO_PI / sideCount; } endShape(CLOSE); }