public class JTurtle
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private java.awt.geom.Point2D |
addedPoint |
(package private) static int |
HEIGHT |
(package private) double |
myHeading |
(package private) java.awt.geom.Point2D |
myLinePoint |
private java.util.List<TurtleListener> |
myListeners |
(package private) java.awt.geom.Point2D |
myNextPoint |
(package private) java.awt.geom.Point2D |
myPoint |
(package private) Renderer |
myRenderer |
boolean |
pen |
(package private) static int |
START_X |
(package private) static int |
START_Y |
(package private) static java.util.ArrayList<java.awt.geom.Point2D> |
trail |
boolean |
visible |
(package private) static int |
WIDTH |
Modifier | Constructor and Description |
---|---|
|
JTurtle()
Create a turtle using the default (triangle) image.
|
|
JTurtle(java.awt.Image img)
Creates a turtle using the given image
|
private |
JTurtle(Renderer renderer) |
Modifier and Type | Method and Description |
---|---|
void |
addTurtleListener(TurtleListener listener)
Add a listener.
|
void |
clearLine()
Clears all points within the trail so that the line can be erased.
|
void |
draw(java.awt.Graphics g)
Draw the turtle, pass in a Graphics2D object.
|
void |
drawLine(java.awt.Graphics g) |
void |
drawOldLine(java.util.ArrayList<java.awt.geom.Point2D> al,
java.awt.Graphics g) |
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.lang.String |
getPen() |
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.
|
boolean |
setPenDown() |
boolean |
setPenDownHome() |
boolean |
setPenUp() |
void |
setPoint(java.awt.geom.Point2D p)
Sets the turtles point, notifies listeners.
|
protected double |
trueHeading()
Return the real/true heading of the turtle.
|
double myHeading
java.awt.geom.Point2D myPoint
java.awt.geom.Point2D myNextPoint
java.awt.geom.Point2D myLinePoint
Renderer myRenderer
public boolean pen
public boolean visible
static java.util.ArrayList<java.awt.geom.Point2D> trail
private java.awt.geom.Point2D addedPoint
static final int START_X
static final int START_Y
static final int WIDTH
static final int HEIGHT
private java.util.List<TurtleListener> myListeners
public JTurtle()
public JTurtle(java.awt.Image img)
img
- the image to use for the turtleprivate JTurtle(Renderer renderer)
public 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 drawOldLine(java.util.ArrayList<java.awt.geom.Point2D> al, java.awt.Graphics g)
protected double trueHeading()
public void move(int steps)
steps
- is the number of steps movedpublic void drawLine(java.awt.Graphics g)
public 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 pointpublic boolean setPenUp()
public boolean setPenDown()
public boolean setPenDownHome()
public java.lang.String getPen()
public void clearLine()