slogo.gui
Class Turtle

java.lang.Object
  extended by slogo.gui.Turtle
All Implemented Interfaces:
java.lang.Cloneable

public class Turtle
extends java.lang.Object
implements java.lang.Cloneable

This class is a simple SLogo turtle model for illustrating rudimentary MVC for turtles and simple Graphics2D concepts

Author:
Owen Astrachan, gehmane, richardsonw

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

visible

boolean visible

myHeading

double myHeading

myPoint

java.awt.geom.Point2D myPoint

myLastPoint

java.awt.geom.Point2D myLastPoint

myRenderer

Renderer myRenderer

connectTheDots

private java.util.ArrayList<PenLine> connectTheDots

isPenDown

private boolean isPenDown

myPenColor

private java.awt.Color myPenColor

startX

private int startX

startY

private int startY

WIDTH

static final int WIDTH
See Also:
Constant Field Values

HEIGHT

static final int HEIGHT
See Also:
Constant Field Values

myListeners

private java.util.List<TurtleListener> myListeners
Constructor Detail

Turtle

public Turtle()
Create a turtle using the default (triangle) image. In a more general architecture the image/shape might be passed in at construction time too.


Turtle

public Turtle(java.awt.Image img)

Turtle

private Turtle(Renderer renderer)
Method Detail

setStartPoint

public void setStartPoint(int x,
                          int y)

getStartX

public int getStartX()

getStartY

public int getStartY()

getPenColor

public java.awt.Color getPenColor()

setPenColor

public void setPenColor(java.awt.Color c)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

setVisibility

public void setVisibility(boolean v)

getVisibility

public boolean getVisibility()

clone

public java.lang.Object clone()
I don't know why this doesn't work. No, you cannot clone the turtle right now

Overrides:
clone in class java.lang.Object

translatePoint

private java.awt.Point translatePoint(java.awt.geom.Point2D point)
Translate the center point to a "drawable" point

Returns:
the center point into the coordinates for a "drawable" point

getBounds

public java.awt.Rectangle getBounds(java.awt.Rectangle r)
Mirrors the functionality of JComponent/Component. The current turtle isn't a Component, but it sort of acts like one (it's drawable).

See Also:
Component.getBounds()

reset

public void reset()
Reposition turtle at the origin, facing north.


home

public void home()
Reposition turtle at the origin


clean

public void clean()

draw

public void draw(java.awt.Graphics g)
Draw the turtle, pass in a Graphics2D object.

Parameters:
g - is the graphics context in which Turtle is drawn

trueHeading

protected double trueHeading()
Return the real/true heading of the turtle. A Turtle's "heading" is what naive users would expect, i.e., 0 degrees == north, 90 degrees = east, -90 degrees = west. The trueheading translates to what Graphics/geometry expects

Returns:
the true heading in radians

move

public void move(int steps)
Moves the turtle forward.

Parameters:
steps - is the number of steps moved

getTowardsHeading

public double getTowardsHeading(java.awt.geom.Point2D p)
Returns:
a double representing the angle (in degrees) between the two points.

setHeading

public void setHeading(int degrees)
Set heading in degrees, notify listeners.

Parameters:
degrees - will be Turtle's new heading

setHeading

public void setHeading(double radians)
Set heading in radians, notify listeners.

Parameters:
radians - Turtle's new heading

rotate

public void rotate(int degrees)
Turn the turtle by a specified amount

Parameters:
degrees - the amount the turtle should turn

getHeading

public double getHeading()
Returns the naive view of heading, 0 degrees = north

Returns:
the heading

getHeadingInDegrees

public int getHeadingInDegrees()

getPoint

public java.awt.geom.Point2D getPoint()
Returns the turtle's point (should be centroid)

Returns:
the center point

notifyListeners

public void notifyListeners()
Ask all registered listeners to process this turtle


copy

public 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.

Parameters:
other -

addTurtleListener

public void addTurtleListener(TurtleListener listener)
Add a listener.

Parameters:
listener - is the listener added

setPoint

public void setPoint(java.awt.geom.Point2D p)
Sets the turtles point, notifies listeners.

Parameters:
p - is the new center point

setPoint

public void setPoint(double xcord,
                     double ycord)

getIsPenDown

public boolean getIsPenDown()
Returns boolean value of pen position

Returns:
true if pen is down (drawing) and false if pen is up (not drawing)

setPenToDown

public void setPenToDown(boolean pen)
Allows user to set the pen position for the turtle

Parameters:
pen - set pen to true to draw, set pen to false to stop drawing