|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectterrapin.Terrapin
public class Terrapin
Terrapin class, making ideas from the LOGO teaching language available in Processing.
| 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 |
|---|
public int x
public int y
public int drawColor
public boolean drawing
public final processing.core.PApplet applet
| Constructor Detail |
|---|
public Terrapin(processing.core.PApplet applet)
applet - PApplet to render to.public Terrapin(Terrapin t)
t - Terrapin to copy.| Method Detail |
|---|
public void backward(int amount)
amount - number of pixels to move by.public void forward(int amount)
amount - number of pixels to move by.
public int getDistance(int otherX,
int otherY)
otherX - location in x axis.otherY - location in y axis.
public int getDistance(Terrapin t)
t - the other Terrapin.
public Terrapin getNearest(java.util.List<Terrapin> Terrapins)
Terrapins - the list.
public int getRotation()
public void left(int amount)
amount - angle in degrees.
public void moveToward(int toX,
int toY,
float amount)
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.
public void moveToward(int toX,
int toY,
int amount)
toX - location in x.toY - location in y.amount - number of pixels to move toward (x,y).
public void moveToward(Terrapin t,
float amount)
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.moveToward(int, int, float)
public void moveToward(Terrapin t,
int amount)
t - Terrapin to move towards.amount - number of pixels to move toward (x,y).moveToward(int, int, int)public void randomPenColor()
public void right(int amount)
amount - angle in degrees.
public void setLocation(int x,
int y)
x - location in x axis.y - location in y axis.public void setPenColor(int color)
color - a colour created with
PApplet.color(int, int, int).
public void setPenColor(int r,
int g,
int b)
r - red value, 0-255.g - green value, 0-255.b - blue value, 0-255.public void setRotation(int rotation)
rotation - angle in degrees.public void strafeLeft(int amount)
amount - number of pixels to strafe Terrapin.public void strafeRight(int amount)
amount - number of pixels to strafe Terrapin.public java.lang.String toString()
toString in class java.lang.Object
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||