public class JTurtle
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
java.awt.Color |
color |
(package private) static int |
HEIGHT |
java.util.ArrayList<TurtleLine> |
lines |
(package private) double |
myHeading |
private java.util.List<TurtleListener> |
myListeners |
java.awt.geom.Point2D |
myNextPoint |
java.awt.geom.Point2D |
myPoint |
(package private) Renderer |
myRenderer |
(package private) Renderer |
newRenderer |
private boolean |
penDown |
float |
penWidth |
private boolean |
showing |
(package private) static int |
START_X |
(package private) static int |
START_Y |
(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 |
changeRenderer(java.awt.Image img) |
void |
clearLines()
Clears the turtles lines, notifies listeners.
|
void |
draw(java.awt.Graphics g)
Draw the turtle if showing, 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.Color |
getPenColor() |
float |
getPenWidth() |
java.awt.geom.Point2D |
getPoint()
Returns the turtle's point (should be centroid)
|
void |
hideTurtle() |
boolean |
isPenDown() |
void |
move(int steps)
Moves the turtle forward.
|
void |
notifyListeners()
Ask all registered listeners to process this turtle
|
void |
penDown()
Enables the turtle to draw lines
|
void |
penUp()
Disables the turtle to draw lines
|
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 |
setPenColor(java.awt.Color c) |
void |
setPenWidth(float w) |
void |
setPoint(java.awt.geom.Point2D p)
Sets the turtles point, notifies listeners.
|
void |
showTurtle() |
protected double |
trueHeading()
Return the real/true heading of the turtle.
|
boolean |
turtleShowing() |
Renderer newRenderer
double myHeading
public java.awt.geom.Point2D myPoint
public java.awt.geom.Point2D myNextPoint
Renderer myRenderer
private boolean penDown
public java.util.ArrayList<TurtleLine> lines
public java.awt.Color color
public float penWidth
private boolean showing
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 changeRenderer(java.awt.Image img)
public void hideTurtle()
public void showTurtle()
public boolean turtleShowing()
protected double trueHeading()
public void move(int steps)
steps
- is the number of steps movedpublic void penDown()
public void penUp()
public boolean isPenDown()
public void setPenColor(java.awt.Color c)
public java.awt.Color getPenColor()
public void setPenWidth(float w)
public float getPenWidth()
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 void clearLines()