public class JTurtle
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
(package private) static int |
HEIGHT |
private java.awt.Image |
image |
(package private) java.awt.geom.Point2D |
intermediatePoint |
(package private) double |
myHeading |
private java.util.List<TurtleListener> |
myListeners |
(package private) java.awt.geom.Point2D |
myNextPoint |
(package private) java.awt.geom.Point2D |
myPoint |
(package private) Renderer |
myRenderer |
private TurtlePen |
pen |
(package private) static int |
START_X |
(package private) static int |
START_Y |
(package private) 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)
Creates a turtle using a renderer
|
Modifier and Type | Method and Description |
---|---|
void |
addLineSegmentDuringMove(double deltaX,
double deltaY)
adds a lineSegment during the move
|
private java.awt.geom.Point2D |
addOffsetToPoint(java.awt.geom.Point2D point)
Adds Offset to the point
|
void |
addTurtleListener(TurtleListener listener)
Add a listener.
|
void |
changeImage(java.awt.Image img)
Changes the image
|
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.Image |
getImage()
Get the image
|
TurtlePen |
getPen()
Gets the turtle's pen.
|
java.awt.geom.Point2D |
getPoint()
Returns the turtle's point (should be centroid)
|
boolean |
getVisibility()
Returns the turtle's visibility (true or false)
|
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 |
setPen(TurtlePen pen)
Sets the pen
|
void |
setPoint(java.awt.geom.Point2D p)
Sets the turtles point, notifies listeners.
|
void |
setVisibility(boolean visible)
Sets visibility
|
protected double |
trueHeading()
Return the real/true heading of the turtle.
|
private java.awt.Image image
boolean visible
double myHeading
java.awt.geom.Point2D myPoint
java.awt.geom.Point2D myNextPoint
java.awt.geom.Point2D intermediatePoint
Renderer myRenderer
static final int START_X
static final int START_Y
static final int WIDTH
static final int HEIGHT
private TurtlePen pen
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)
renderer
- is the renderer used to create 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 drawnprotected double trueHeading()
public void move(int steps)
steps
- is the number of steps movedpublic void addLineSegmentDuringMove(double deltaX, double deltaY)
deltaX
- is the change in x during the movedeltaY
- is the change in y during the moveprivate java.awt.geom.Point2D addOffsetToPoint(java.awt.geom.Point2D point)
point
- is the point to be offsetpublic 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 boolean getVisibility()
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 void changeImage(java.awt.Image img)
img
- is the image to change topublic java.awt.Image getImage()
public TurtlePen getPen()
public void setPen(TurtlePen pen)
pen
- is the pen that is setpublic void setVisibility(boolean visible)
visible
- is whether or not it is visible