![]() |
CS111 Turtle Contract |
Instances of the Turtle
class represent
whimsical creatures that inhabit an instance of
the TurtleWorld
class. Conceptually, every
turtle has four abstract state variables:
double
values, unlike
buggle coordinates, which are int
values.
double
value that expresses an
angle between 0 and 360 degrees. 0 degrees
points rightward along the x-axis.
true
/false
) indicating
whether the turtle's pen is down.
Constructor Methods
Turtle ()
Returns a new turtle at position (0.0,0.0) whose heading is
0
, whose color is Color.red
, and whose pen
is down.
Instance Methods
public void fd(int n)
public void fd(double n)
Moves this turtle forward by length n
in the direction of its current heading.
public void bd (int n)
public void bd (double n)
Moves this turtle backward by length n
in the direction of its current heading.
public void lt (int angle)
public void lt (double angle)
Turns this turtle left by angle
degrees.
public void rt (int angle)
public void lt (double angle)
Turns this turtle right by angle
degrees.
public void pu ()
Raises this turtle's pen. When the pen is raised, the turtle leaves no trail when it moves.
public void pd ()
Lowers this turtle's pen. When the pen is lowered, the turtle leaves a trail when it moves.
public Point getPosition ()
Returns a point that indicates the current position of this turtle in turtleworld.
public void setPosition (Point p)
Changes the position of this turtle to be the point p
.
public void setPosition (int x, int y)
public void setPosition (double x, double y)
Changes the position of this turtle to be (x,y)
.
public double getHeading ()
Returns the heading of this turtle.
public void setHeading (int d)
public void setHeading (double d)
Changes the heading of this turtle to be the angle d
.
public Color getColor ()
Returns the color of this turtle.
public void setColor (Color c)
Changes the color of this turtle to be the color c
.
public String toString ()
Returns a string representation of this turtle.