Constructor and Description |
---|
GTurtle()
Creates a new
GTurtle object. |
GTurtle(double x,
double y)
Creates a new
GPen positioned at the point
(x , y ). |
Modifier and Type | Method and Description |
---|---|
boolean |
contains(double x,
double y)
Contains is defined to be false for the
GPen object to avoid having the
trace intercept mouse clicks. |
void |
erasePath()
Erases the entire path drawn by the turtle but does not change its position.
|
void |
forward()
Moves the turtle forward by its own size.
|
void |
forward(double distance)
Moves the turtle forward in its current direction by the specified distance.
|
GRectangle |
getBounds()
Returns the bounding box for the entire figure traced by the turtle.
|
double |
getDirection()
Returns the direction specified by
setDirection . |
double |
getSpeed()
Returns the current speed of the turtle.
|
int |
getTurtleSize()
Returns the size of the turtle.
|
void |
hideTurtle()
Hides the turtle.
|
boolean |
isPenDown()
Returns whether the pen is down, as described in
setPenDown . |
boolean |
isTurtleVisible()
Returns whether the turtle is visible.
|
void |
left(double angle)
Changes the direction of the turtle so that it moves the specified number
of degrees to the left.
|
static void |
main(java.lang.String[] args)
Makes it possible for a
GTurtle to be run under the control
of a GraphicsProgram object. |
void |
move(double dx,
double dy)
Moves the turtle by the specified displacements.
|
void |
paint(java.awt.Graphics g)
Implements the
paint operation for this graphical object. |
void |
penDown()
Lowers the pen.
|
void |
penUp()
Raises the pen.
|
void |
right(double angle)
Changes the direction of the turtle so that it moves the specified number
of degrees to the right.
|
void |
setColor(java.awt.Color color)
Sets the color of the turtle's pen.
|
void |
setDirection(double dir)
Sets the direction in which the turtle is moving.
|
void |
setLocation(double x,
double y)
Moves the turtle to the point (
x , y ) without drawing a line. |
void |
setSize(int size)
Sets the size of the turtle.
|
void |
setSpeed(double speed)
Sets the speed of the turtle, which must be a number between 0 (slowest)
and 1 (fastest).
|
void |
showTurtle()
Makes the turtle visible.
|
addActionListener, addMouseListener, addMouseMotionListener, contains, fireActionEvent, fireActionEvent, getColor, getHeight, getLocation, getParent, getSize, getWidth, getX, getY, isVisible, movePolar, pause, removeActionListener, removeMouseListener, removeMouseMotionListener, sendBackward, sendForward, sendToBack, sendToFront, setLocation, setParent, setVisible, toString
public GTurtle()
GTurtle
object.public GTurtle(double x, double y)
GPen
positioned at the point
(x
, y
).x
- The initial x coordinate of the turtley
- The initial y coordinate of the turtlepublic void erasePath()
public void setLocation(double x, double y)
x
, y
) without drawing a line.setLocation
in class GObject
x
- The x-coordinate of the new positiony
- The y-coordinate of the new positionpublic void move(double dx, double dy)
GObject
superclass but will usually be avoided in
favor of forward
.public void forward(double distance)
distance
- The distance to move in the current directionpublic final void forward()
public void setDirection(double dir)
dir
- The direction in which the turtle is movingpublic double getDirection()
setDirection
.public final void left(double angle)
angle
- The angle to turn, measured in degreespublic final void right(double angle)
angle
- The angle to turn, measured in degreespublic boolean isPenDown()
setPenDown
.true
if the pen is down, false
otherwisepublic final void penDown()
public final void penUp()
public void setColor(java.awt.Color color)
public boolean isTurtleVisible()
true
if the turtle is visible, otherwise false
public final void showTurtle()
public final void hideTurtle()
public void setSpeed(double speed)
speed
- The speed of the turtle (0 is slowest, 1 is fastest)public double getSpeed()
public void setSize(int size)
The
- size of the turtle image in pixelspublic int getTurtleSize()
public void paint(java.awt.Graphics g)
paint
operation for this graphical object. This method
is not called directly by clients.public GRectangle getBounds()
public boolean contains(double x, double y)
GPen
object to avoid having the
trace intercept mouse clicks.public static void main(java.lang.String[] args)
GTurtle
to be run under the control
of a GraphicsProgram
object.args
- An array of string arguments