galapagos
Class TurtleShape

java.lang.Object
  extended by galapagos.TurtleShape

 class TurtleShape
extends java.lang.Object

A class responsible for maintaining and manipulating the turtle shape. Modified: Feb 24, 2009

Author:
Dr Caffeine

Field Summary
private  java.awt.Color color
          The fill color of this body shape
private static java.awt.Color DEFAULT_COLOR
          The default color of this body shape
private  java.awt.Point[] shape
          An array of Point objects to represent the turtle's shape in the local coordinate system.
private static int SHAPE_SIZE
          The size of an array to store the points of the robot shape.
 
Constructor Summary
TurtleShape()
          A default constructor for a standard turtle shape.
 
Method Summary
private  Position compose(Position turtlePosition, double turtleOrientation, java.awt.Point refPoint)
          Compute a position of reference point in the global coordinate system.
 java.awt.Color getColor()
          Returns the current fill color of this body shape.
 java.awt.Polygon getShape(Position turtlePosition, double turtleOrientation)
          Computes a polygon that represents the turtle's shape.
private  void initShape()
          Initializes the default shape (array) for the turtle.
(package private)  void setColor(java.awt.Color color)
          Sets the fill color for this body shape
(package private)  void setRefShape(java.awt.Point[] points)
          Sets the reference body shape for this turtle shape.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_COLOR

private static final java.awt.Color DEFAULT_COLOR
The default color of this body shape


SHAPE_SIZE

private static final int SHAPE_SIZE
The size of an array to store the points of the robot shape.

See Also:
Constant Field Values

shape

private java.awt.Point[] shape
An array of Point objects to represent the turtle's shape in the local coordinate system. Given a turtle's position, we can compute the points of the turtle shape in global values from this array.


color

private java.awt.Color color
The fill color of this body shape

Constructor Detail

TurtleShape

public TurtleShape()
A default constructor for a standard turtle shape.

Method Detail

getColor

public java.awt.Color getColor()
Returns the current fill color of this body shape.

Returns:
the current fill color of this body shape

getShape

public java.awt.Polygon getShape(Position turtlePosition,
                                 double turtleOrientation)
Computes a polygon that represents the turtle's shape.

Parameters:
turtlePosition - The turtle's current position
turtleOrientation - The turtle's orientation in radian
Returns:
A polygon for the turtle shape specified in the global coordinate system.

setRefShape

void setRefShape(java.awt.Point[] points)
Sets the reference body shape for this turtle shape. Define the shape relative to (0,0), the pen point.

Parameters:
points - An array of java.awt.Point objects

setColor

void setColor(java.awt.Color color)
Sets the fill color for this body shape

Parameters:
color - a new Color for this body shape

compose

private Position compose(Position turtlePosition,
                         double turtleOrientation,
                         java.awt.Point refPoint)
Compute a position of reference point in the global coordinate system.

Parameters:
turtlePosition - the turtle's current position
turtleOrientation - the turtle's current orientation
refPoint - the point in the local coordinate system
Returns:
A position of point in the global coordinate system

initShape

private void initShape()
Initializes the default shape (array) for the turtle. Elements in the array provide polygon coordinate points in pixels relative to the turtle's position which is (0,0) in the local coordinate system.