import java.awt.*; // Import Abstract Window Toolkit import java.applet.*; // Import Applet stuff public class NestedPolygonWorld extends TurtleWorld { String parameterNames [] = {"size", "number"}; ParameterFrame params; public void setup() { params = new ParameterFrame(" Parameters",200, 50, parameterNames); } public void run() { PolygonMaker polly = new PolygonMaker(); // Move to good initial position using simple geometry double size = params.getDoubleParam("size"); int number = params.getIntParam("number"); double innerAngle; if (number>0) { innerAngle = 360/number; } else { innerAngle = 120; } double halfInnerAngle = innerAngle/2; double innerRadius = (size/2) / Math.sin(halfInnerAngle*Math.PI/180); polly.pu(); polly.lt(90-halfInnerAngle); polly.bd(innerRadius); polly.rt(90-halfInnerAngle); polly.pd(); polly.nestEquiPolygons(size, number); } } class PolygonMaker extends Turtle { public void nestEquiPolygons(double size, int number) { System.out.println("nestEquiPolygons("+size+", "+number+");"); if (number>0) { equiPolygon(size,number+2); nestEquiPolygons(size,number-1); } } public void equiPolygon(double size, int sides) { System.out.println("equiPolygon("+size+", "+sides+")"); double outerAngle = 360.0/sides; equiPolySide(size, outerAngle, sides); } public void equiPolySide(double size, double angle, int count) { System.out.println("equiPolySide("+size+", "+angle+", "+count+")"); if (count>0) { fd(size); lt(angle); equiPolySide(size, angle, count-1); } } }