public class JTurtle
extends java.lang.Object
Constructor and Description |
---|
JTurtle()
Create a turtle using the default (triangle) image.
|
JTurtle(java.awt.Image img)
Creates a turtle using the given image
|
Modifier and Type | Method and Description |
---|---|
void |
addTurtleListener(TurtleListener listener)
Add a listener.
|
void |
draw(java.awt.Graphics g)
Draw the turtle, pass in a Graphics2D object.
|
java.awt.Rectangle |
getBounds(java.awt.Rectangle r)
Mirrors the functionality of JComponent/Component.
|
double |
getHeading()
Returns the naive view of heading, 0 degrees = north
|
java.awt.geom.Point2D |
getPoint()
Returns the turtle's point (should be centroid)
|
void |
move(int steps)
Moves the turtle forward.
|
void |
notifyListeners()
Ask all registered listeners to process this turtle
|
void |
reset()
Reposition turtle at the origin, facing north.
|
void |
setHeading(double radians)
Set heading in radians, notify listeners.
|
void |
setHeading(int degrees)
Set heading in degrees, notify listeners.
|
void |
setPoint(java.awt.geom.Point2D p)
Sets the turtles point, notifies listeners.
|
public JTurtle()
public JTurtle(java.awt.Image img)
img
- the image to use for the turtlepublic java.awt.Rectangle getBounds(java.awt.Rectangle r)
Component.getBounds()
public void reset()
public void draw(java.awt.Graphics g)
g
- is the graphics context in which Turtle is drawnpublic void move(int steps)
steps
- is the number of steps movedpublic void setHeading(int degrees)
degrees
- will be Turtle's new headingpublic void setHeading(double radians)
radians
- Turtle's new headingpublic double getHeading()
public java.awt.geom.Point2D getPoint()
public void notifyListeners()
public void addTurtleListener(TurtleListener listener)
listener
- is the listener addedpublic void setPoint(java.awt.geom.Point2D p)
p
- is the new center point