// Drawing spirals with turtles. import java.awt.*; // Import Abstract Window Toolkit import java.applet.*; // Import Applet stuff public class SpiralWorld extends TurtleWorld { String parameterNames [] = {"Steps", "Angle", "Length", "Increment"}; String parameterFields [] = {"5", "144", "200", "0"}; ParameterFrame params; //------------------------------------------------------------------------------ // The following main method is needed to run the applet as an application public static void main (String[] args) { runAsApplication(new SpiralWorld(), "SpiralWorld"); } //------------------------------------------------------------------------------ public void setup() { params = new ParameterFrame("Spiral Parameters", TurtleWorld.frameSize, 0, 173, 165, parameterNames, parameterFields); } public void run() { SpiralMaker spiro = new SpiralMaker(); spiro.spiral(params.getIntParam("Steps"), params.getIntParam("Angle"), params.getIntParam("Length"), params.getIntParam("Increment")); } } class SpiralMaker extends Turtle { public void spiral (int steps, int angle, int length, int increment) { if (steps <= 0) { // Do nothing } else { fd(length); lt(angle); spiral(steps - 1, angle, length+increment, increment); } } }