/** * Class for creating a template for a simple Java program * * @author Pat Troy: troy AT uic DOT edu */ // import the library with the color information import java.awt.Color; // Note the name of the class in the following line MUST // match the name of the file. This is stored in a file // named: Template.java public class Lect921e { public static void main (String[] args) { System.out.println("Begin Java Exection"); System.out.println(""); // Select a picture for the turtle to draw on Picture pict1 = new Picture(600, 600); // Create the turlte and place it in the world Turtle t = new Turtle (pict1); t.setPenWidth(5); // Using a loop draw multiple hexagons int loopCounter = 1; //int numLoops = SimpleInput.getIntNumber("Specify the number of Hexagons to draw", 1, 60); int numLoops = 12; int degrees = 360 / numLoops; int length; while ( loopCounter <= numLoops ) { length = 40 + (loopCounter * 10) ; //length = 120; t.setPenColor (new Color( loopCounter * 20, 0, 255 - (loopCounter * 20)) ); drawHexagon (t, length); t.turn (degrees); loopCounter ++; } // display the picture pict1.show(); // Save the picture //String fname; //fname = FileChooser.pickAFile(); //System.out.println ("File: " + filename); //pict1.write (fname); System.out.println(""); System.out.println("End Java Exection"); } // end of the method main public static void drawSquare (Turtle tParam) { int len = 40; tParam.forward (len); tParam.turn (90); tParam.forward (len); tParam.turn (90); tParam.forward (len); tParam.turn (90); tParam.forward (len); tParam.turn (90); } public static void drawSquare (Turtle tParam, int len) { tParam.forward (len); tParam.turn (90); tParam.forward (len); tParam.turn (90); tParam.forward (len); tParam.turn (90); tParam.forward (len); tParam.turn (90); } public static void drawSquare (Turtle tParam, int len, Color c) { Color currentColor = tParam.getPenColor(); tParam.setPenColor (c); tParam.forward (len); tParam.turn (90); tParam.forward (len); tParam.turn (90); tParam.forward (len); tParam.turn (90); tParam.forward (len); tParam.turn (90); tParam.setPenColor (currentColor); } public static void drawTriangle (Turtle tParam, int len) { tParam.forward (len); tParam.turn (120); tParam.forward (len); tParam.turn (120); tParam.forward (len); tParam.turn (120); } public static void drawHexagon (Turtle tParam, int len) { int degrees = 60; int loopCounter; loopCounter = 1; while ( loopCounter <= 6 ) { tParam.forward (len); tParam.turn (degrees); loopCounter = loopCounter + 1; } } } // end of Lect914b class