import java.awt.*; // Import Abstract Window Toolkit import java.applet.*; // Import Applet stuff // Drawing snowflakes (Koch curves) with turtles. public class SnowflakeWorld extends TurtleWorld { String parameterNames [] = {"Levels", "Length"}; String parameterFields [] = {"1", "200"}; ParameterFrame params; //------------------------------------------------------------------------------ // The following main method is needed to run the applet as an application public static void main (String[] args) { runAsApplication(new SnowflakeWorld(), "SnowflakeWorld"); } //------------------------------------------------------------------------------ public void setup() { params = new ParameterFrame("Snowflake Parameters", TurtleWorld.frameSize,0, 140, 110, parameterNames, parameterFields); } public void run() { SnowflakeMaker snowy = new SnowflakeMaker(); // Use a little geometry to start of in nice spot double radius = 0.75 * (params.getIntParam("Length") / Math.sqrt(3)); snowy.pu(); snowy.lt(90); snowy.fd(radius/4); snowy.rt(120); snowy.bd(radius); snowy.lt(30); snowy.pd(); snowy.snowflake(params.getIntParam("Levels"), (double) params.getIntParam("Length")); } } class SnowflakeMaker extends Turtle { public void snowflake (int levels, double length) { snowside(levels, length); rt(120); snowside(levels, length); rt(120); snowside(levels, length); rt(120); } public void snowside (int levels, double length) { if (levels == 0) { fd(length); } else { snowside(levels - 1, length/3); lt(60); snowside(levels - 1, length/3); rt(120); snowside(levels - 1, length/3); lt(60); snowside(levels - 1, length/3); } } }