public class Turtle
extends java.lang.Object
Constructor and Description |
---|
Turtle()
Creates a white turtle using the following defaults:
- Turtle color white - Position (0, 0), center of playground - Pen color white - Heading north |
Turtle(double x,
double y)
Creates a white turtle at given position using the following other defaults:
- Pen color white - Heading north |
Turtle(double x,
double y,
int color)
Creates a turtle with given color at given position using the
following other defaults:
- Pen color white - Heading north |
Turtle(int color)
Creates a turtle with given color using the
following other defaults:
- Position (0, 0), center of playground - Pen color white - Heading north |
Modifier and Type | Method and Description |
---|---|
Turtle |
back(double s)
Moves the turtle back.
|
static void |
beep()
Emits a beep (1000 Hz sine wave of 100 ms duration).
|
Turtle |
bk(double s)
Short for back().
|
static void |
clean()
Erases the playground by filling it with the current playground color.
|
static void |
clean(int color)
Erases the playground by filling it with the given color.
|
static void |
clear()
Clears the playground by filling it with the current playground color.
|
static void |
clear(int color)
Clears the playground by filling it with the given color.
|
Turtle |
clone()
Creates a clone of the current turtle by performing a
deep copy of all its properties.
|
double |
distance(double x,
double y)
Returns the distance from the current position to the given position.
|
Turtle |
dot()
Draws a single point (dot) at the current turtle position using the
current pen color.
|
Turtle |
fd(double s)
Short for forward().
|
Turtle |
fill()
Same as fill(x, y), but uses the current turtle position.
|
Turtle |
fill(double x,
double y)
Fills a bounded region of the playground with the current
pen color (flood fill).
|
Turtle |
fillOff()
Stops the filling started by calling fillToPoint(),
fillToHorizontal() or fillToVertical().
|
Turtle |
fillToHorizontal(double y)
Draws a imaginary horizonatal line at given y coordinate.
|
Turtle |
fillToPoint(double x,
double y)
Attachs a imaginary rubber band between the turtle and the given
anchor point.
|
Turtle |
fillToVertical(double x)
Draws a imaginary vertical line at given x coordinate.
|
Turtle |
forward(double s)
Moves the turtle forward.
|
turtle.Actor |
getActor()
Returns the underlying turtle actor.
|
int |
getColor()
Returns the current turtle color.
|
double |
getHeading()
Returns the current heading (moving direction).
|
int |
getPenColor()
Returns the current pen color.
|
int |
getPenWidth()
Returns the current pen width.
|
static int |
getPopulationSize()
Get the total number of turtles (the global turtle is not counted).
|
int |
getSpeed()
Returns the current speed (0..10, -1 for MAXSPEED).
|
double |
getX()
Returns the current x coordinate.
|
double |
getY()
Returns the current y coordinate.
|
Turtle |
hideTurtle()
Hides the turtle.
|
Turtle |
home()
Puts the turtle at home (center of playground, coordinates (0, 0).
|
Turtle |
ht()
Short for hideTurtle().
|
boolean |
isBackValid(double s)
Checks if the backward movement using the given step moves
the turtle to a position outside the visible playground.
|
boolean |
isForwardValid(double s)
Checks if the forward movement using the given step moves
the turtle to a position outside the visible playground.
|
boolean |
isHidden()
Reports the current visibility of the turtle.
|
boolean |
isInPlayground()
Checks, if the turtle is inside or outside the playground.
|
boolean |
isOnBorder()
Returns true, if the turtle is on any of the 4 border lines.
|
boolean |
isOnBorder(int borderId)
Returns true, if the turtle is on the selected border line.
|
boolean |
isPenDown()
Reports the current pen state of the turtle.
|
Turtle |
label(java.lang.String text)
Same as label(text, textColor, textSize) with textColor = Color.WHITE
and textSize = 15.
|
Turtle |
label(java.lang.String text,
int textColor,
int textSize)
Paint the given text with given text color and given text height
at the current turtle position
|
Turtle |
left(double angle)
Turns the turtle to the left (counter clockwise).
|
Turtle |
lt(double angle)
Short for left().
|
Turtle |
moveTo(double x,
double y)
Moves the turtle to the given position.
|
Turtle |
pd()
Short for penDown().
|
Turtle |
penDown()
Lowers the turtle's pen, so it draws traces when it moves.
|
Turtle |
penUp()
Lifts the turtle's pen, so is does not draw traces when it moves.
|
Turtle |
pu()
Short for penUp().
|
Turtle |
right(double angle)
Turns the turtle to the right (clockwise).
|
Turtle |
rt(double angle)
Short for right().
|
Turtle |
setColor(int color)
Sets the current turtle color.
|
Turtle |
setHeading(double heading)
Sets the current heading (moving direction).
|
Turtle |
setPenColor(int color)
Sets the current pen color.
|
Turtle |
setPenWidth(int width)
Sets the current pen width.
|
Turtle |
setPos(double x,
double y)
Puts the turtle to the given position.
|
Turtle |
setSize(int size)
Sets the current turtle size.
|
Turtle |
setSpeed(int speed)
Sets the turtle's speed.
|
Turtle |
setX(double x)
Puts the turtle to the given x coordinate.
|
Turtle |
setY(double y)
Puts the turtle to the given y coordinate.
|
Turtle |
showTurtle()
Shows the turtle if it was hidden before.
|
static void |
sleep(int time)
Delays the execution for the given time.
|
Turtle |
st()
Short for showTurtle().
|
double |
towards(double x,
double y)
Returns the direction (heading) from the current position
to the given position.
|
public Turtle()
public Turtle(int color)
color
- the initial color of the turtle (may be Color.TRANSPARENT
to make the turtle invisible from the beginning)public Turtle(double x, double y)
x
- the x coordinate of the creation positiony
- the y coordinate of the creation positionpublic Turtle(double x, double y, int color)
x
- the x coordinate of the creation positiony
- the y coordinate of the creation positioncolor
- the initial color of the turtle (may be Color.TRANSPARENT
to make the turtle invisible from the beginning)public Turtle setSpeed(int speed)
speed
- the speed of the turtle (0..10, MAXSPEED)public int getSpeed()
public Turtle forward(double s)
s
- the step to move forward, if s < 0 moves backpublic Turtle fd(double s)
public Turtle back(double s)
s
- the step to move back, if s < 0 moves forwardpublic Turtle bk(double s)
public Turtle right(double angle)
angle
- the turning angle (in degrees), if angle < 0 turns leftpublic Turtle rt(double angle)
public Turtle left(double angle)
angle
- the turning angle (in degrees), if angle < 0 turns rightpublic Turtle lt(double angle)
public static void beep()
public static int getPopulationSize()
public static void clean()
public static void clean(int color)
public static void clear()
public static void clear(int color)
public Turtle hideTurtle()
public Turtle ht()
public boolean isHidden()
public Turtle showTurtle()
public Turtle st()
public int getColor()
public Turtle setColor(int color)
public Turtle setSize(int size)
size
- one of the constants Playground.SMALLSIZE, Playground.MEDIUMSIZE,
Playground.BIGSIZEpublic double getHeading()
public Turtle setHeading(double heading)
heading
- in degrees, 0 to north, clockwisepublic double towards(double x, double y)
x
- the x coordinate of the target positiony
- the y coordinate of the target positionpublic Turtle home()
public boolean isPenDown()
public Turtle penDown()
public Turtle pd()
public Turtle penUp()
public Turtle pu()
public int getPenWidth()
public Turtle setPenWidth(int width)
width
- the pen width in pixels (independent of current screen resolution)public int getPenColor()
public Turtle setPenColor(int color)
public Turtle label(java.lang.String text)
public Turtle label(java.lang.String text, int textColor, int textSize)
text
- the text to showtextColor
- the text colortextSize
- the text size in turtle coordinatespublic double distance(double x, double y)
x
- the x coordinate of the target positiony
- the y coordinate of the target positionpublic double getX()
public double getY()
public Turtle setPos(double x, double y)
x
- the new turtle's x coordinatey
- the new turtle's y coordinatepublic Turtle moveTo(double x, double y)
x
- the new turtle's x coordinatey
- the new turtle's y coordinatepublic Turtle dot()
public Turtle setX(double x)
x
- the new turtle's x coordinatepublic Turtle setY(double y)
y
- the new turtle's y coordinatepublic static void sleep(int time)
time
- the time to wait (in ms)public Turtle fill(double x, double y)
x
- the x coordinate of a point inside the regiony
- the y coordinate of a point inside the regionpublic Turtle fill()
public turtle.Actor getActor()
public boolean isOnBorder()
public boolean isOnBorder(int borderId)
borderId
- 0: top border, 1: right border, 2: bottom border, 3: left borderpublic boolean isForwardValid(double s)
s
- the step to move forward, if s < 0 moves backpublic boolean isBackValid(double s)
s
- the step to move back, if s < 0 moves forwardpublic Turtle fillToPoint(double x, double y)
x
- the x coordinate of the anchor pointy
- the y coordinate of the anchor pointpublic Turtle fillToHorizontal(double y)
y
- the y coordinate of the horizontal linepublic Turtle fillToVertical(double x)
x
- the x coordinate of the vertical linepublic boolean isInPlayground()
public Turtle fillOff()
public Turtle clone()
clone
in class java.lang.Object