|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectslogo.gui.Turtle
public class Turtle
This class is a simple SLogo turtle model for illustrating rudimentary MVC for turtles and simple Graphics2D concepts
Field Summary | |
---|---|
private java.util.ArrayList<PenLine> |
connectTheDots
|
(package private) static int |
HEIGHT
|
private boolean |
isPenDown
|
(package private) double |
myHeading
|
(package private) java.awt.geom.Point2D |
myLastPoint
|
private java.util.List<TurtleListener> |
myListeners
|
private java.awt.Color |
myPenColor
|
(package private) java.awt.geom.Point2D |
myPoint
|
(package private) Renderer |
myRenderer
|
private int |
startX
|
private int |
startY
|
(package private) boolean |
visible
|
(package private) static int |
WIDTH
|
Constructor Summary | |
---|---|
|
Turtle()
Create a turtle using the default (triangle) image. |
|
Turtle(java.awt.Image img)
|
private |
Turtle(Renderer renderer)
|
Method Summary | |
---|---|
void |
addTurtleListener(TurtleListener listener)
Add a listener. |
void |
clean()
|
java.lang.Object |
clone()
I don't know why this doesn't work. |
void |
copy(Turtle other)
This method allows the current Turtle object to acquire the attributes of another Turtle object without cloning and building new objects. |
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 |
int |
getHeadingInDegrees()
|
boolean |
getIsPenDown()
Returns boolean value of pen position |
java.awt.Color |
getPenColor()
|
java.awt.geom.Point2D |
getPoint()
Returns the turtle's point (should be centroid) |
int |
getStartX()
|
int |
getStartY()
|
double |
getTowardsHeading(java.awt.geom.Point2D p)
|
boolean |
getVisibility()
|
void |
home()
Reposition turtle at the origin |
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 |
rotate(int degrees)
Turn the turtle by a specified amount |
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 |
setPenToDown(boolean pen)
Allows user to set the pen position for the turtle |
void |
setPoint(double xcord,
double ycord)
|
void |
setPoint(java.awt.geom.Point2D p)
Sets the turtles point, notifies listeners. |
void |
setStartPoint(int x,
int y)
|
void |
setVisibility(boolean v)
|
java.lang.String |
toString()
|
private java.awt.Point |
translatePoint(java.awt.geom.Point2D point)
Translate the center point to a "drawable" point |
protected double |
trueHeading()
Return the real/true heading of the turtle. |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
boolean visible
double myHeading
java.awt.geom.Point2D myPoint
java.awt.geom.Point2D myLastPoint
Renderer myRenderer
private java.util.ArrayList<PenLine> connectTheDots
private boolean isPenDown
private java.awt.Color myPenColor
private int startX
private int startY
static final int WIDTH
static final int HEIGHT
private java.util.List<TurtleListener> myListeners
Constructor Detail |
---|
public Turtle()
public Turtle(java.awt.Image img)
private Turtle(Renderer renderer)
Method Detail |
---|
public void setStartPoint(int x, int y)
public int getStartX()
public int getStartY()
public java.awt.Color getPenColor()
public void setPenColor(java.awt.Color c)
public java.lang.String toString()
toString
in class java.lang.Object
public void setVisibility(boolean v)
public boolean getVisibility()
public java.lang.Object clone()
clone
in class java.lang.Object
private java.awt.Point translatePoint(java.awt.geom.Point2D point)
public java.awt.Rectangle getBounds(java.awt.Rectangle r)
Component.getBounds()
public void reset()
public void home()
public void clean()
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 double getTowardsHeading(java.awt.geom.Point2D p)
public void setHeading(int degrees)
degrees
- will be Turtle's new headingpublic void setHeading(double radians)
radians
- Turtle's new headingpublic void rotate(int degrees)
degrees
- the amount the turtle should turnpublic double getHeading()
public int getHeadingInDegrees()
public java.awt.geom.Point2D getPoint()
public void notifyListeners()
public void copy(Turtle other)
other
- public void addTurtleListener(TurtleListener listener)
listener
- is the listener addedpublic void setPoint(java.awt.geom.Point2D p)
p
- is the new center pointpublic void setPoint(double xcord, double ycord)
public boolean getIsPenDown()
public void setPenToDown(boolean pen)
pen
- set pen to true to draw, set pen to false to stop drawing
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |