public class Turtle extends Object
(X_LEFT, Y_BOTTOM)
and (X_RIGHT, Y_TOP)
.
The angle of the turtle is measured relative to the positive xaxis, and
the turtle ensures that the angle is always greater than 360 degrees and
less than +360 degrees.Modifier and Type  Field and Description 

static double 
X_LEFT
The xcoordinate of the left edge of the square.

static double 
X_RIGHT
The xcoordinate of the right edge of the square.

static double 
Y_BOTTOM
The ycoordinate of the bottom edge of the square.

static double 
Y_TOP
The ycoordinate of the top edge of the square.

Constructor and Description 

Turtle()
Create a turtle located at the exact middle of the square with an angle of
0.0 degrees and a pen color of Color.BLACK . 
Turtle(Turtle other)
Create a turtle from another turtle.

Turtle(Vector2D position,
double angle,
Color c)
Create a turtle with the given starting position, angle, and pen color.

Modifier and Type  Method and Description 

double 
getAngle()
Gets the direction that the turtle is facing in as an angle measured from
the x axis.

Color 
getPenColor()
Gets the current pen color.

Vector2D 
getPosition()
Gets the current position of the turtle.

static void 
main(String[] args)
This main method tests that the turtle stays inside the square.

void 
move(double distance)
Moves the turtle by a given distance in the direction the turtle is
currently facing.

void 
setPenColor(Color c)
Sets the pen color.

String 
toString()
Returns a string representation of this turtle.

void 
turn(double delta)
Turns the turtle by the specified amount in degrees.

void 
turnLeft()
Turns the turtle to the left, increasing its angle by 90.0 degrees.

void 
turnRight()
Turns the turtle to the right, decreasing its angle by 90.0 degrees.

public static final double X_LEFT
public static final double X_RIGHT
public static final double Y_BOTTOM
public static final double Y_TOP
public Turtle()
0.0
degrees and a pen color of Color.BLACK
.public Turtle(Turtle other)
other
 the turtle to copypublic Turtle(Vector2D position, double angle, Color c)
(X_LEFT, Y_BOTTOM)
and (X_RIGHT, Y_TOP)
,
otherwise an IllegalArgumentException
will be thrown.IllegalArgumentException
 if the starting position is
not in the square with corners (X_LEFT, Y_BOTTOM)
and
(X_RIGHT, Y_TOP)
position
 the starting position of the turtleangle
 the angle in degrees from the x axis that the turtle is facing inc
 the pen colorpublic void move(double distance)
The turtle will not move outside the square with corners having coordinates
(X_LEFT, Y_BOTTOM)
and (X_RIGHT, Y_TOP)
. If the
specified distance would cause the turtle to move outside of the square,
then the turtle will move as far as possible in its current direction and
then stop at the perimeter of the square.
IllegalArgumentException
 if the distance is less than zerodistance
 the distance to movepublic void turnLeft()
public void turnRight()
public void turn(double delta)
delta
turns the turtle to the left (counterclockwise) and the
negative delta
turns the turtle to the right (clockwise). The
angle of the turtle is always corrected to be greater than
360
degrees and less than +360
degrees.delta
 the amount by which to turn the turtlepublic void setPenColor(Color c)
c
 the new pen colorpublic Color getPenColor()
public Vector2D getPosition()
Vector2D
returned by this
method. To move the turtle the client must use move
.public double getAngle()
360
degrees and +360
degrees.public String toString()
(0.5, 0.5), 0.0 degrees, java.awt.Color[r=0,g=0,b=0]
toString
in class Object
Object.toString()
public static void main(String[] args)
(0.9999999989999999, 0.5), 0.0 degrees, java.awt.Color[r=0,g=0,b=0] (0.9999999989999999, 0.9999999989999999), 90.0 degrees, java.awt.Color[r=0,g=0,b=255] (9.999999717180685E10, 0.999999999), 180.0 degrees, java.awt.Color[r=255,g=0,b=0] (9.999997880210491E10, 9.999999717180685E10), 270.0 degrees, java.awt.Color[r=0,g=255,b=0] (0.999999999, 9.999999717180685E10), 0.0 degrees, java.awt.Color[r=128,g=128,b=128]
args
 not used