|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectpturtle.Turtle
public class Turtle
Turtle 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 Turtle (as a Processing color). |
boolean |
drawing
If false, the Turtle moves but does not leave a trail. |
int |
x
x location on screen. |
int |
y
y location on screen. |
Constructor Summary | |
---|---|
Turtle(processing.core.PApplet applet)
Standard constructor, creates a Turtle in the middle of the screen which draws in white. |
|
Turtle(Turtle t)
"Copy" constructor, creates an identical Turtle to the one passed in. |
Method Summary | |
---|---|
void |
backward(int amount)
Move Turtle backward. |
void |
forward(int amount)
Move Turtle forward. |
int |
getDistance(int otherX,
int otherY)
Get the distance between this Turtle and point (x,y). |
int |
getDistance(Turtle t)
Get the distance between this Turtle and another. |
Turtle |
getNearest(java.util.List<Turtle> turtles)
Get the nearest (Euclidean distance) Turtle from a List. |
int |
getRotation()
Get the angle that the Turtle is facing. |
void |
left(int amount)
Turn the Turtle left. |
void |
moveToward(int toX,
int toY,
float amount)
Move the Turtle toward point (x,y). |
void |
moveToward(int toX,
int toY,
int amount)
Move the Turtle a specified number of pixels toward point (x,y). |
void |
moveToward(Turtle t,
float amount)
Move Turtle toward another. |
void |
moveToward(Turtle t,
int amount)
Move Turtle toward another. |
void |
randomPenColor()
Randomise the colour that the Turtle draws with from a set of 16 hard-coded colours. |
void |
right(int amount)
Turn the Turtle right. |
void |
setLocation(int x,
int y)
Move the Turtle to an absolute location. |
void |
setPenColor(int color)
Set the colour the Turtle draws with. |
void |
setPenColor(int r,
int g,
int b)
Set the colour the Turtle draws with. |
void |
setRotation(int rotation)
Set the direction the Turtle is facing in to an absolute angle. |
void |
strafeLeft(int amount)
Strafe the Turtle left. |
void |
strafeRight(int amount)
Strafe the Turtle right. |
java.lang.String |
toString()
Convert the Turtle 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 Turtle(processing.core.PApplet applet)
applet
- PApplet to render to.public Turtle(Turtle t)
t
- Turtle 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(Turtle t)
t
- the other turtle.
public Turtle getNearest(java.util.List<Turtle> turtles)
turtles
- 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 turtle, 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(Turtle t, float amount)
t
- Turtle 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 turtle, 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(Turtle t, int amount)
t
- Turtle 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 Turtle.public void strafeRight(int amount)
amount
- number of pixels to strafe Turtle.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 |