World w = new World(); Turtle t = new Turtle(w); int i; // draw a red square of size 100 t.setPenColor (Color.red); i = 0; while ( i < 4 ) { t.forward (100); t.turn (90); i++; } // move into the inside of the red square t.penUp(); t.forward (10); t.turn (90); t.forward (10); t.turn (-90); t.penDown(); // draw a blue sqaure of size 80 t.setPenColor (Color.blue); i = 0; while ( i < 4 ) { t.forward (80); t.turn (90); i++; } // show the drawing w.show();
public static void drawQ22 (Turtle t, int len, Color c) { Color c2 = t.getPenColor (); int i = 0; int numSides = 12; t.setPenColor (c); // draw the dodecagon while ( i < numSides ) { t.forward (len); t.turn (360 / numSides); // 360/12 = 30 i++; } t.setPenColor (c2); }