Class Turtle

java.lang.Object
  extended by Turtle

public class Turtle
extends Object

An instance is a turtle in a panel within a JFrame. A turtle is a spot on the panel that you can move from place to place. All instances of Turtle use the same JFrame and panel.


Field Summary
static int height
          The panel on which the turtle moves is of size (width, height).
static int width
          The panel on which the turtle moves is of size (width, height).
 
Constructor Summary
Turtle()
          Constructor: a black turtle starting at the middle of the panel with angle 0 (looking east).
Turtle(double x, double y, double ang)
          Constructor: a black turtle starting at (x,y) with angle ang.
 
Method Summary
 void addAngle(double ang)
          Add ang degrees to the angle.
 void clear()
          Clear the screen (make it all white).
 void drawCircle(double d)
          Draw a circle with center at current pen position of diameter d.
 void drawRectangle(double w, double h)
          Draw a rectangle with center at current pen position of width w, height h.
 void fillCircle(double d)
          Fill a circle with center at current pen position of diameter d.
 void fillRectangle(double w, double h)
          Fill a rectangle with center at current pen position of width w, height h.
 double getAngle()
          = angle of the turtle (in degrees).
 Color getColor()
          = the current color.
 int getHeight()
          = height of the panel.
 int getWidth()
          = width of panel.
 double getX()
          = x-coordinate of the turtle.
 double getY()
          = y-coordinate of the panel.
 void liftPen()
          Lift pen.
 void move(double d)
          Move the turtle d units in its current direction.
 void moveTo(double x, double y, double ang)
          Move the turtle to (x,y), without drawing, and face it at angle ang.
 void pause(int msec)
          Pause the program for msec milliseconds.
 void putPenDown()
          Put pen down.
 void setAngle(double ang)
          Set the angle to ang degrees.
 void setColor(Color c)
          Set the color of the turtle to c.
 void setPanelSize()
          Set panel size as big as possible in the current window.
static Color tColor(int c)
          = the Color value for c.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

width

public static int width
The panel on which the turtle moves is of size (width, height).


height

public static int height
The panel on which the turtle moves is of size (width, height).

Constructor Detail

Turtle

public Turtle()
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.


Turtle

public Turtle(double x,
              double y,
              double ang)
Constructor: a black turtle starting at (x,y) with angle ang. East (right) is angle 0; north (up), 90; west (left), 180; South (down), 270. The pen is down.

Method Detail

tColor

public static Color tColor(int c)
= the Color value for c. The values are as follows: 1 black, 2 blue, 3 cyan, 4 dark gray, 5 gray, 6 green, 7 light gray, 8 magenta, 9 orange, 10 pink, 11 red, 12 white, 13 yellow, any other integer black.


setPanelSize

public void setPanelSize()
Set panel size as big as possible in the current window.


getX

public double getX()
= x-coordinate of the turtle.


getY

public double getY()
= y-coordinate of the panel.


getAngle

public double getAngle()
= angle of the turtle (in degrees). East (right) is angle 0; north (up), 90; west (left), 180; South (down), 270.


getWidth

public int getWidth()
= width of panel.


getHeight

public int getHeight()
= height of the panel.


setAngle

public void setAngle(double ang)
Set the angle to ang degrees. East (right) is angle 0; north (up), 90; west (left), 180; South (down), 270.


addAngle

public void addAngle(double ang)
Add ang degrees to the angle.


liftPen

public void liftPen()
Lift pen.


putPenDown

public void putPenDown()
Put pen down.


setColor

public void setColor(Color c)
Set the color of the turtle to c.


getColor

public Color getColor()
= the current color.


moveTo

public void moveTo(double x,
                   double y,
                   double ang)
Move the turtle to (x,y), without drawing, and face it at angle ang.


drawCircle

public void drawCircle(double d)
Draw a circle with center at current pen position of diameter d.


fillCircle

public void fillCircle(double d)
Fill a circle with center at current pen position of diameter d.


drawRectangle

public void drawRectangle(double w,
                          double h)
Draw a rectangle with center at current pen position of width w, height h.


fillRectangle

public void fillRectangle(double w,
                          double h)
Fill a rectangle with center at current pen position of width w, height h.


move

public void move(double d)
Move the turtle d units in its current direction. If the pen is down, a line will be drawn; if the pen is up, it won't be drawn.


clear

public void clear()
Clear the screen (make it all white).


pause

public void pause(int msec)
Pause the program for msec milliseconds.