/* * Regular Polygon implementation modeled after that on page 92 of Greenberg,Xu,Kumar text. * * In this version, the user must also specified the center coordinates (cx,cy), * and a rotational angle, theta, at which the first point is placed relative * to the center. * * Sketch by Michael Goldwasser */ void setup() { size(600,600); background(255); strokeWeight(2); fill(255, 0, 0); regularPolygon(8, 0.4*width, 0.5*width, 0.5*height, 0.125*PI); // may as well finish the stop sign fill(255); textAlign(CENTER, CENTER); // not quite perfect, but close textSize(0.25 * width); text("STOP", 0.5*width, 0.5*height); } void draw() { } /** * Draws a regularly polygon having sideCount sides and * indicated radius, centered at (cx,cy) and with a vertex * positioned at angle theta from the center. */ void regularPolygon(int sideCount, float radius, float cx, float cy, float theta) { beginShape(); for (int i=0; i < sideCount; i++) { float x = cx + radius * cos(theta); float y = cy + radius * sin(theta); vertex(x,y); theta += TWO_PI / sideCount; } endShape(CLOSE); }