Class A5

java.lang.Object
  extended by Turtle
      extended by A5

public class A5
extends Turtle

Assignment A5


Constructor Summary
A5()
          Constructor: a black turtle starting at the middle of the panel with angle 0 (looking east).
 
Method Summary
 void drawGreenHex(int d)
          Draw six green equilateral triangles with side lengths d to form a hexagon, starting at the turtle's current position and angle.
 void drawH(double x, double y, double s)
          Draw an H at center (x, y) of size s.
 void drawPolygon(int n, int d)
          Draw an n-sided polygon, ending up with the turtle being where it started out and facing the same direction, and with the pen properties the same, too.
 void drawSpiral(int ms, int n, int ang, int d)
          Draw a spiral of n lines, beginning at the current turtle position and angle, using an angle of ang between adjacent lines and pausing ms milliseconds after each line.
 void drawSpiralMid(int ms, int n, int ang, int d)
          Do as in drawSpiral but clear screen and start at the center of the panel and angle 0.
 void drawTriangle(int e, Color c)
          Draw an equilateral triangle of side length e and color c at the turtle's current position.
 void drawTwoLines()
          Draw a black line 30 pixels to the right (east) and then a blue line 35 pixels down (south).
 void fillSquare(double s)
          Fill a square of size (s, s), with top-left corner at the turtle's position.
static Color HSV2RGB(HSV HSV)
          = color in RGB color space formulae from http://en.wikipedia.org/wiki/HSV_color_space
 void multiPolygons(int m, int n, int d)
          Draw 90 n-sided polygons of side length d, alternating between blue and red.
 void placeInCenter()
          Place the turtle in the center of the panel, facing east, and clear the window (make it white).
 void radiate(int m, int n, int d)
          Draw n straight radiating lines of length d at equal angles.
 void radiateMid(int m, int n, int d)
          Do as in radiate but clear screen and start at center of panel and angle 0.
 void recursiveH(double x, double y, int d, double s)
          Make the graphics panel as big as possible, clear the panel, and draw an H-tree of depth d with center (x, y) and size s.
 void recursiveH1(double x, double y, int d, double s)
          draw an H-tree of depth d with center (x, y) and size s.
 void sierpinski(double x, double y, int d, double s)
          Make the graphics panel as big as possible, clear the panel, and draw a Sierpinksi triangle of depth d with side length s with the bottom left corner (x,y).
 void sierpinskicarpet(double x, double y, int d, double s)
          Make the graphics panel as big as possible, clear the panel, and draw a Sierpinksi carpet of depth d with side length s.
 String toString()
          = a representation of this Turtle, giving its position, the angle, it is facing, whether the pen is down, and its color.
 
Methods inherited from class Turtle
addAngle, clear, drawCircle, drawRect, fillCircle, fillRect, fillTriangle, getAngle, getColor, getCommands, getHeight, getWidth, getX, getY, intColor, isPenDown, jumpTo, moveAhead, moveBack, pause, putPenDown, putPenUp, setAngle, setColor, setPanelSize
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

A5

public A5()
Constructor: a black turtle starting at the middle of the panel with angle 0 (looking east). East (right) is angle 0; north (up), 90; west (left), 180; South (down). 270. The pen is down.

Method Detail

drawTwoLines

public void drawTwoLines()
Draw a black line 30 pixels to the right (east) and then a blue line 35 pixels down (south). Precondition: the turtle is facing east.


placeInCenter

public void placeInCenter()
Place the turtle in the center of the panel, facing east, and clear the window (make it white).


toString

public String toString()
= a representation of this Turtle, giving its position, the angle, it is facing, whether the pen is down, and its color.

Overrides:
toString in class Object

drawTriangle

public void drawTriangle(int e,
                         Color c)
Draw an equilateral triangle of side length e and color c at the turtle's current position. UPON COMPLETION, THE following properties SHOULD BE THE SAME AS WHEN THE METHOD STARTED: turtle position, turtle direction, pen color, and whether the pen is up or down. Precondition: the pen is down.


drawGreenHex

public void drawGreenHex(int d)
Draw six green equilateral triangles with side lengths d to form a hexagon, starting at the turtle's current position and angle. Precondition: the pen is down.


drawSpiralMid

public void drawSpiralMid(int ms,
                          int n,
                          int ang,
                          int d)
Do as in drawSpiral but clear screen and start at the center of the panel and angle 0.


drawSpiral

public void drawSpiral(int ms,
                       int n,
                       int ang,
                       int d)
Draw a spiral of n lines, beginning at the current turtle position and angle, using an angle of ang between adjacent lines and pausing ms milliseconds after each line. Line 1 is d pixels long; line 2, 2*d pixels, ..., so each line i is d*i pixels long. The lines should alternate between blue, red, and green, in that order, with the first one being blue. End with the pen properties being the same as before the call.


radiateMid

public void radiateMid(int m,
                       int n,
                       int d)
Do as in radiate but clear screen and start at center of panel and angle 0.


radiate

public void radiate(int m,
                    int n,
                    int d)
Draw n straight radiating lines of length d at equal angles. Pause m milliseconds after each line. A line drawn at angle ang, 0 <= ang < 360, should be drawn with the HSV color (ang, 1, 1). Precondition: n >= 2.


HSV2RGB

public static Color HSV2RGB(HSV HSV)
= color in RGB color space formulae from http://en.wikipedia.org/wiki/HSV_color_space


drawPolygon

public void drawPolygon(int n,
                        int d)
Draw an n-sided polygon, ending up with the turtle being where it started out and facing the same direction, and with the pen properties the same, too. Each side is d pixels long.


multiPolygons

public void multiPolygons(int m,
                          int n,
                          int d)
Draw 90 n-sided polygons of side length d, alternating between blue and red. Each one starts at the same place, but each one is at an angle 4 degrees more than the preceding one. Pause m milliseconds after each one. All properties of the turtle are the same at the end as they were in the beginning.


sierpinski

public void sierpinski(double x,
                       double y,
                       int d,
                       double s)
Make the graphics panel as big as possible, clear the panel, and draw a Sierpinksi triangle of depth d with side length s with the bottom left corner (x,y). Precondition: d >= 0 and s > 0.


sierpinskicarpet

public void sierpinskicarpet(double x,
                             double y,
                             int d,
                             double s)
Make the graphics panel as big as possible, clear the panel, and draw a Sierpinksi carpet of depth d with side length s. The turtle is positioned at the top left point of the carpet. Precondition: d >= 0 and s > 0.


fillSquare

public void fillSquare(double s)
Fill a square of size (s, s), with top-left corner at the turtle's position. Upon completion, the turtle should be at its original position.


drawH

public void drawH(double x,
                  double y,
                  double s)
Draw an H at center (x, y) of size s.


recursiveH

public void recursiveH(double x,
                       double y,
                       int d,
                       double s)
Make the graphics panel as big as possible, clear the panel, and draw an H-tree of depth d with center (x, y) and size s. Precondition: d >= 0 and s >= 0 and w >= 0.


recursiveH1

public void recursiveH1(double x,
                        double y,
                        int d,
                        double s)
draw an H-tree of depth d with center (x, y) and size s. Precondition: d >= 0 and s >= 0.