terrapin
Class Terrapin

java.lang.Object
  extended by terrapin.Terrapin
Direct Known Subclasses:
HistoryTerrapin

public class Terrapin
extends java.lang.Object

Terrapin class, making ideas from the LOGO teaching language available in Processing.

Author:
George Bashi, Ollie Glass

Field Summary
 processing.core.PApplet applet
          The PApplet to render to.
 int drawColor
          Colour of line drawn by Terrapin (as a Processing color).
 boolean drawing
          If false, the Terrapin moves but does not leave a trail.
 int x
          x location on screen.
 int y
          y location on screen.
 
Constructor Summary
Terrapin(processing.core.PApplet applet)
          Standard constructor, creates a Terrapin in the middle of the screen which draws in white.
Terrapin(Terrapin t)
          "Copy" constructor, creates an identical Terrapin to the one passed in.
 
Method Summary
 void backward(int amount)
          Move Terrapin backward.
 void forward(int amount)
          Move Terrapin forward.
 int getDistance(int otherX, int otherY)
          Get the distance between this Terrapin and point (x,y).
 int getDistance(Terrapin t)
          Get the distance between this Terrapin and another.
 Terrapin getNearest(java.util.List<Terrapin> Terrapins)
          Get the nearest (Euclidean distance) Terrapin from a List.
 int getRotation()
          Get the angle that the Terrapin is facing.
 void left(int amount)
          Turn the Terrapin left.
 void moveToward(int toX, int toY, float amount)
          Move the Terrapin toward point (x,y).
 void moveToward(int toX, int toY, int amount)
          Move the Terrapin a specified number of pixels toward point (x,y).
 void moveToward(Terrapin t, float amount)
          Move Terrapin toward another.
 void moveToward(Terrapin t, int amount)
          Move Terrapin toward another.
 void randomPenColor()
          Randomise the colour that the Terrapin draws with from a set of 16 hard-coded colours.
 void right(int amount)
          Turn the Terrapin right.
 void setLocation(int x, int y)
          Move the Terrapin to an absolute location.
 void setPenColor(int color)
          Set the colour the Terrapin draws with.
 void setPenColor(int r, int g, int b)
          Set the colour the Terrapin draws with.
 void setRotation(int rotation)
          Set the direction the Terrapin is facing in to an absolute angle.
 void strafeLeft(int amount)
          Strafe the Terrapin left.
 void strafeRight(int amount)
          Strafe the Terrapin right.
 java.lang.String toString()
          Convert the Terrapin to a String representation
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

x

public int x
x location on screen.


y

public int y
y location on screen.


drawColor

public int drawColor
Colour of line drawn by Terrapin (as a Processing color).


drawing

public boolean drawing
If false, the Terrapin moves but does not leave a trail.


applet

public final processing.core.PApplet applet
The PApplet to render to.

Constructor Detail

Terrapin

public Terrapin(processing.core.PApplet applet)
Standard constructor, creates a Terrapin in the middle of the screen which draws in white.

Parameters:
applet - PApplet to render to.

Terrapin

public Terrapin(Terrapin t)
"Copy" constructor, creates an identical Terrapin to the one passed in.

Parameters:
t - Terrapin to copy.
Method Detail

backward

public void backward(int amount)
Move Terrapin backward.

Parameters:
amount - number of pixels to move by.

forward

public void forward(int amount)
Move Terrapin forward.

Parameters:
amount - number of pixels to move by.

getDistance

public int getDistance(int otherX,
                       int otherY)
Get the distance between this Terrapin and point (x,y).

Parameters:
otherX - location in x axis.
otherY - location in y axis.
Returns:
distance in pixels.

getDistance

public int getDistance(Terrapin t)
Get the distance between this Terrapin and another.

Parameters:
t - the other Terrapin.
Returns:
distance in pixels.

getNearest

public Terrapin getNearest(java.util.List<Terrapin> Terrapins)
Get the nearest (Euclidean distance) Terrapin from a List.

Parameters:
Terrapins - the list.
Returns:
the nearest Terrapin.

getRotation

public int getRotation()
Get the angle that the Terrapin is facing.

Returns:
angle in degrees.

left

public void left(int amount)
Turn the Terrapin left.

Parameters:
amount - angle in degrees.

moveToward

public void moveToward(int toX,
                       int toY,
                       float amount)
Move the Terrapin toward point (x,y).

Parameters:
toX - location in x axis.
toY - location in y axis.
amount - value between 0 and 1 as a ratio of how close to move toward point (x,y); 0 will not move the Terrapin, 1 will cause it to jump straight to (x,y), 0.5f will cause it to move half way there, etc.

moveToward

public void moveToward(int toX,
                       int toY,
                       int amount)
Move the Terrapin a specified number of pixels toward point (x,y).

Parameters:
toX - location in x.
toY - location in y.
amount - number of pixels to move toward (x,y).

moveToward

public void moveToward(Terrapin t,
                       float amount)
Move Terrapin toward another.

Parameters:
t - Terrapin to move towards.
amount - value between 0 and 1 as a ratio of how close to move toward point (x,y); 0 will not move the Terrapin, 1 will cause it to jump straight to (x,y), 0.5f will cause it to move half way there, etc.
See Also:
moveToward(int, int, float)

moveToward

public void moveToward(Terrapin t,
                       int amount)
Move Terrapin toward another.

Parameters:
t - Terrapin to move towards.
amount - number of pixels to move toward (x,y).
See Also:
moveToward(int, int, int)

randomPenColor

public void randomPenColor()
Randomise the colour that the Terrapin draws with from a set of 16 hard-coded colours.


right

public void right(int amount)
Turn the Terrapin right.

Parameters:
amount - angle in degrees.

setLocation

public void setLocation(int x,
                        int y)
Move the Terrapin to an absolute location. This does not draw.

Parameters:
x - location in x axis.
y - location in y axis.

setPenColor

public void setPenColor(int color)
Set the colour the Terrapin draws with.

Parameters:
color - a colour created with PApplet.color(int, int, int).

setPenColor

public void setPenColor(int r,
                        int g,
                        int b)
Set the colour the Terrapin draws with.

Parameters:
r - red value, 0-255.
g - green value, 0-255.
b - blue value, 0-255.

setRotation

public void setRotation(int rotation)
Set the direction the Terrapin is facing in to an absolute angle.

Parameters:
rotation - angle in degrees.

strafeLeft

public void strafeLeft(int amount)
Strafe the Terrapin left.

Parameters:
amount - number of pixels to strafe Terrapin.

strafeRight

public void strafeRight(int amount)
Strafe the Terrapin right.

Parameters:
amount - number of pixels to strafe Terrapin.

toString

public java.lang.String toString()
Convert the Terrapin to a String representation

Overrides:
toString in class java.lang.Object
Returns:
"Terrapin at 100,100"


processing library Terrapin by George Bashi and Ollie Glass. (c) 2007