Class Turtle

java.lang.Object
  extended by Turtle

public class Turtle
extends Object

An instance is a turtle in a panel within a JFrame. The turtle is a spot on the panel, facing a certain direction and holding a colored pen. You can move the turtle from place to place, drawing as the turtle moves. You can ask the turtle to pick the pen up so that moving doesn't draw. You can draw rectangles and circles of any size around the turtle. All instances of Turtle use the same JFrame and panel.


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 of diameter d with center at the turtle's position.
 void drawRect(double w, double h)
          Draw a rectangle of width w, height h with center at the turtle's position.
 void fillCircle(double d)
          Fill a circle of diameter d with center at the turtle's position.
 void fillRect(double w, double h)
          Fill a rectangle of width w, height h with center at the turtle's position.
 void fillTriangle(double s)
          Fill triangle with lower left point at the turtle position and side length s.
 double getAngle()
          = angle of the turtle (in degrees).
 Color getColor()
          = the turtle's current color.
static String getCommands()
          = all the turtle commands carried out since the last clear(), one to a line.
 int getHeight()
          = height of the panel.
 int getWidth()
          = width of panel.
 double getX()
          = x-coordinate of the turtle.
 double getY()
          = y-coordinate of the turtle.
static Color intColor(int i)
          = the Color value for integer i.
 boolean isPenDown()
          = "the pen is down".
 void jumpTo(double x, double y, double ang)
          Move the turtle to (x,y), without drawing, and face it at angle ang --who ever heard of turtles jumping?
 void moveAhead(double d)
          Move the turtle d units in its current direction.
 void moveBack(double d)
          Move the turtle d units in the opposite (backward) direction.
 void pause(int millisec)
          Pause the program for millisec milliseconds.
 void putPenDown()
          Put pen down.
 void putPenUp()
          Lift pen.
 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 the panel size as big as possible in the current JFrame window.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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

getCommands

public static String getCommands()
= all the turtle commands carried out since the last clear(), one to a line.


intColor

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


setPanelSize

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


getX

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


getY

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


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.


isPenDown

public boolean isPenDown()
= "the pen is down".


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.


putPenUp

public void putPenUp()
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 turtle's current color.


jumpTo

public void jumpTo(double x,
                   double y,
                   double ang)
Move the turtle to (x,y), without drawing, and face it at angle ang --who ever heard of turtles jumping?


drawCircle

public void drawCircle(double d)
Draw a circle of diameter d with center at the turtle's position.


fillTriangle

public void fillTriangle(double s)
Fill triangle with lower left point at the turtle position and side length s. Don't move the turtle.


fillCircle

public void fillCircle(double d)
Fill a circle of diameter d with center at the turtle's position.


drawRect

public void drawRect(double w,
                     double h)
Draw a rectangle of width w, height h with center at the turtle's position.


fillRect

public void fillRect(double w,
                     double h)
Fill a rectangle of width w, height h with center at the turtle's position.


moveAhead

public void moveAhead(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.


moveBack

public void moveBack(double d)
Move the turtle d units in the opposite (backward) 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 millisec)
Pause the program for millisec milliseconds.