class TrailPolygon extends TrailShape { int nSides; TrailPolygon(float x, float y, float dx, float dy, float size, float dSizePercent, color sColor, int nSides) { super(x, y, dx, dy, size, dSizePercent, sColor); this.nSides = nSides; } /** * Draws an equilateral polygon with sides of the * given size, centered at (x,y). * * It works by figuring out the length of a line from * the center of the polygon to the outer edge (called * interiorLength). A line from (0,0) to (interiorlength, 0) * is rotated in steps of 360/nSides to determine the * vertices of the polygon. * */ void drawShape(float x, float y, float size) { float interiorLength = size / 2 * cos(radians(90.0 * (nSides - 2) / nSides)); float dTheta = 360.0 / nSides; float vx = interiorLength; float vy = 0; beginShape(); for (int i = 0; i <= nSides; i++) { vertex(x + vx, y + vy); vx = interiorLength * cos(radians(i * dTheta)); vy = interiorLength * sin(radians(i * dTheta)); } endShape(CLOSE); } }