Constructor and Description |
---|
GTurtle()
Creates a new
GTurtle object. |
GTurtle(double x,
double y)
Creates a new
GTurtle 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
GTurtle object to avoid
having the trace intercept mouse clicks. |
protected java.awt.Image |
createTurtleImage(double dir)
This method creates (or retrieves) an image of the turtle in the specified
direction.
|
protected void |
drawTurtle(java.awt.Graphics g)
This method draws a representation of the turtle at the current location.
|
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.
|
protected java.awt.Rectangle |
getTurtleBounds()
This method returns the bounds that the turtle occupies.
|
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.
|
protected void |
start()
Starts a
GraphicsProgram containing this object. |
protected void |
start(java.lang.String[] args)
Starts a
GraphicsProgram containing this object, passing it the
specified arguments. |
addActionListener, addMouseListener, addMouseMotionListener, areMouseListenersEnabled, colorName, contains, fireActionEvent, fireActionEvent, fireMouseListeners, getColor, getComponent, getHeight, getLocation, getObjectColor, getParent, getSize, getWidth, getX, getY, isVisible, movePolar, paintObject, paramString, pause, removeActionListener, removeMouseListener, removeMouseMotionListener, repaint, sendBackward, sendForward, sendToBack, sendToFront, setLocation, setParent, setVisible, toString, updateEnabledList
public GTurtle()
GTurtle
object.public GTurtle(double x, double y)
GTurtle
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)
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)
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)
GTurtle
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 argumentsprotected void start()
GraphicsProgram
containing this object.protected void start(java.lang.String[] args)
GraphicsProgram
containing this object, passing it the
specified arguments.protected void drawTurtle(java.awt.Graphics g)
g
- The graphics context in which to draw the turtleprotected java.awt.Rectangle getTurtleBounds()
protected java.awt.Image createTurtleImage(double dir)
dir
- The direction in which the turtle is heading