|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object ch.aplu.gidlet.Turtle
public class Turtle
Logo-like turtle that moves on a graphics display, called playground.
The coordinate system has it's reference point in the middle of the screen
with x-coordinates to the right and y-coordinates upward both in the range
-200..200 (doubles). For simplicity the turtle shape is a triangle. Each
turtle instance has it's own playground. The most recent turtle's playground
is visible, while other playgrounds or Gui windows become hidden. The hidden
windows may be updated in any way, but the change is only visible, when
calling their show() method.
Default colors:
background (playground) color: black
turtle color: light gray
turtle pen color: white
fill color: white
Example:
import ch.aplu.gidlet.*;
public class TurtleGidlet extends Gidlet
{
public void main()
{
Turtle t = new Turtle();
for (int i = 0; i < 18; i++)
{
for (int k = 0; k < 4; k++)
t.forward(100).left(90);
t.left(20);
}
}
}
Nested Class Summary | |
---|---|
protected class |
Turtle.PointD
|
Field Summary | |
---|---|
protected ch.aplu.gidlet.TurtleShape |
shape
|
Constructor Summary | |
---|---|
Turtle()
Constructs a Turtle instance with default background (playground) color and default turtle color. |
|
Turtle(boolean visible)
Constructs a Turtle instance with given visibility, default background (playground) color and default turtle color. |
|
Turtle(int color)
Constructs a Turtle instance with default background (playground) color and given turtle color. |
|
Turtle(int color,
boolean visible)
Constructs a Turtle instance with default background (playground) color, given turtle color and visibility. |
|
Turtle(int bgColor,
int color,
boolean visible)
Constructs a Turtle instance with given background (playground) color, turtle color and visibility. |
|
Turtle(java.lang.String title)
Constructs a Turtle instance with given playground title, default background (playground) color and default turtle color. |
|
Turtle(java.lang.String title,
int bgColor,
int color,
boolean visible)
Constructs a Turtle instance with given playground title, background (playground) color, turtle color and visibility. |
|
Turtle(java.lang.String title,
int bgColor,
int color,
boolean visible,
boolean showPlayground)
Constructs a Turtle instance with given playground title, background (playground) color, turtle color and visibility. |
|
Turtle(Turtle t)
Creates a turtle clone that has exactly the same properties, playground title and traces as the given turtle. |
|
Turtle(Turtle t,
java.lang.String title)
Creates a turtle clone that has exactly the same properties and traces as the given turtle, but the playground has the given title. |
Method Summary | |
---|---|
double |
_getX()
Returns the x-coordinate. |
double |
_getY()
Returns the y-coordinate. |
Turtle |
addKeyListener(KeyListener keyListener)
Registers an KeyListener to get a notification when a button is clicked. |
Turtle |
back(double s)
Moves turtle the given distance backward. |
Turtle |
beep()
Emits a beep. |
Turtle |
bk(double s)
Short for back(). |
Turtle |
clean()
Erases traces and text, but let turtle where it is. |
Turtle |
clear()
Clears the entire playground. |
Turtle |
clip()
Causes turtle not to wrap around playground borders, e.g. when it leaves the playground it disappaers. |
Turtle |
clone()
Creates a new turtle that has exactly the same properties, playground title and traces. |
Turtle |
clone(java.lang.String title)
Creates a new turtle that has exactly the same properties and traces, but the given playground title. |
double |
distance(double x,
double y)
Returns the distance from the current position to the given position. |
Turtle |
drawLabel(int index,
java.lang.String text)
Draws the given text using the current pen color and text font at the current turtle position. |
boolean |
enableRepaint(boolean b)
Enables/disables automatic updating the window after each turtle movement. |
Turtle |
eraseLabel(int index)
Erases the text with given index. |
Turtle |
fd(double s)
Short for forward(). |
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, when the turtle subsequently moves around, the trapezoidal area that is covered by this line and the turtle position is filled using the current fill color. |
Turtle |
fillToPoint(double x,
double y)
Attachs a imaginary rubber band at the given position, when the turtle subsequently moves around, the area that is covered by the rubber band is filled using the current fill color. |
Turtle |
fillToVertical(double x)
Draws a imaginary vertical line at given x-coordinate, when the turtle subsequently moves around, the trapezoidal area that is covered by this line and the turtle position is filled using the current fill color. |
Turtle |
forward(double s)
Moves turtle the given distance forward. |
int |
getColor()
Returns the turtle color. |
Playground |
getPlayground()
Returns the turtle's playground, which is an instance of javax.microedition.lcdui.Canvas. |
double |
getX()
Returns the x-coordinate. |
double |
getY()
Returns the y-coordinate. |
double |
heading()
Returns the angle of vision (angle in respect to north, positive clockwise). |
Turtle |
hideTurtle()
Makes turtle invisible. |
Turtle |
home()
Moves the turtle to the initial position at (0, 0) looking north. |
Turtle |
ht()
Short for hideTurtle(). |
protected void |
init()
Initializes Turtle. |
boolean |
isHidden()
Returns true if turtle is invisible (hidden), otherwise false. |
boolean |
isPenUp()
Returns true if turtle's pen is up, otherwise false. |
boolean |
isWrap()
Returns true, if turtle is in wrap mode, otherwise false. |
Turtle |
left(double angle)
Turns turtle the given angle (in degrees) to the left. |
Turtle |
lt(double angle)
Short for left(). |
Turtle |
pd()
Short for penDown(). |
Turtle |
pe()
Short for penErase(). |
Turtle |
penDown()
Lower pen, so that the trace is drawn. |
Turtle |
penErase()
Changes pen color to the background color. |
Turtle |
penUp()
Lifts pen, so that the trace is not drawn. |
Turtle |
pu()
Short for penUp(). |
Turtle |
removeKeyListener()
Removes a registered KeyListener. |
Turtle |
repaint()
Performs manual repainting when automatic repainting is disabled. |
Turtle |
right(double angle)
Turns turtle the given angle (in degrees) to the right. |
Turtle |
rt(double angle)
Short for right(). |
Turtle |
setColor(int color)
Sets turtle's color to the given color. |
Turtle |
setColor(int r,
int g,
int b)
Sets turtle's color to the given color in RGB-format. |
Turtle |
setDelay(int time)
Sets the given time delay in ms after each turtle movement. |
Turtle |
setFillColor(int color)
Sets the color for subsequent filling. |
Turtle |
setFillColor(int r,
int g,
int b)
Sets the color in RGB-format for subsequent filling. |
Turtle |
setFont(int face,
int style,
int size)
Sets the current text font for drawing labels. |
Turtle |
setH(double angle)
Short for setHeading(). |
Turtle |
setHeading(double angle)
Sets the angle of vision (angle in respect to north, positive clockwise) to the given value (in degrees). |
Turtle |
setPenColor(int color)
Sets turtle's pen color to the given color. |
Turtle |
setPenColor(int r,
int g,
int b)
Sets turtle's pen color to the given color in RGB-format. |
Turtle |
setPos(double x,
double y)
Sets turtle to the given coordinates, without drawing a trace. |
Turtle |
setPosX(double x)
Sets turtle to the given x-position without drawing a trace while the y-coordinate remains unchanged. |
Turtle |
setPosY(double y)
Sets turtle to the given y-position, without drawing a trace while the x-coordinate remains unchanged. |
Turtle |
setX(double x)
Sets turtle to the given x-position, while the y-coordinate remains the same; if pen is down, a trace from the last to the given position is drawn. |
Turtle |
setXY(double x,
double y)
Sets turtle to the given coordinates; if pen is down, a trace from the last to the given position is drawn. |
Turtle |
setY(double y)
Sets turtle to the given y-position, while the x-coordinate remains the same; if pen is down, a trace from the last to the given position is drawn. |
Turtle |
showPlayground()
Shows the playground if it's hidden by another window. |
Turtle |
showTurtle()
Makes turtle visible. |
Turtle |
st()
Short for showTurtle(). |
Turtle |
stampTurtle()
Draws a turtle shape of same color at the current position. |
int |
toPixelX(double x)
Converts from turtle x-coordinates to pixel x-coordinates. |
int |
toPixelY(double y)
Converts from turtle y-coordinates to pixel y-coordinates. |
double |
toTurtleX(int x)
Converts from pixel x-coordinates to turtle x-coordinates. |
double |
toTurtleY(int y)
Converts from pixel y-coordinates to turtle y-coordinates. |
double |
towards(double x,
double y)
Returns the direction from the current to the given position in degrees (-180..180). |
java.lang.String |
version()
Returns version information. |
Turtle |
wrap()
Causes turtle to wrap around playground borders, e.g. when it leaves the playground on one border, it reappears on the opposite border. |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected ch.aplu.gidlet.TurtleShape shape
Constructor Detail |
---|
public Turtle(Turtle t, java.lang.String title)
clone(java.lang.String)
,
showPlayground()
public Turtle(Turtle t)
clone(java.lang.String)
,
showPlayground()
public Turtle(java.lang.String title, int bgColor, int color, boolean visible, boolean showPlayground)
public Turtle(java.lang.String title, int bgColor, int color, boolean visible)
public Turtle(int bgColor, int color, boolean visible)
public Turtle(int color, boolean visible)
public Turtle(int color)
public Turtle(boolean visible)
public Turtle(java.lang.String title)
public Turtle()
Method Detail |
---|
protected void init()
public Turtle forward(double s)
public Turtle fd(double s)
forward(double)
public Turtle back(double s)
public Turtle bk(double s)
back(double)
public Turtle right(double angle)
public Turtle rt(double angle)
right(double)
public Turtle left(double angle)
public Turtle lt(double angle)
left(double)
public double getX()
public double getY()
public double _getX()
public double _getY()
public int getColor()
public Turtle beep()
public Turtle clean()
public Turtle clear()
public double distance(double x, double y)
public double heading()
public Turtle hideTurtle()
public Turtle ht()
hideTurtle()
public boolean isHidden()
public boolean isPenUp()
public Turtle penDown()
public Turtle pd()
penDown()
public Turtle penUp()
public Turtle pu()
penUp()
public Turtle setColor(int color)
public Turtle setColor(int r, int g, int b)
public Turtle setPenColor(int color)
public Turtle setPenColor(int r, int g, int b)
public Turtle penErase()
public Turtle pe()
penErase()
public Turtle setHeading(double angle)
public Turtle setH(double angle)
setHeading(double)
public Turtle setXY(double x, double y)
public Turtle setX(double x)
public Turtle setY(double y)
public Turtle setPos(double x, double y)
public Turtle setPosX(double x)
public Turtle setPosY(double y)
public Turtle showTurtle()
public Turtle st()
showTurtle()
public double toTurtleX(int x)
public double toTurtleY(int y)
public int toPixelX(double x)
public int toPixelY(double y)
public java.lang.String version()
public Turtle wrap()
public boolean isWrap()
wrap()
public Turtle clip()
wrap()
public Turtle drawLabel(int index, java.lang.String text)
eraseLabel(int)
public Turtle eraseLabel(int index)
drawLabel(int, java.lang.String)
public Turtle setFont(int face, int style, int size)
face
- one of Font.FACE_SYSTEM, Font.FACE_MONOSPACE, or Font.FACE_PROPORTIONALstyle
- Font.STYLE_PLAIN, or a combination of Font.STYLE_BOLD, Font.STYLE_ITALIC, and Font.STYLE_UNDERLINEDsize
- one of Font.SIZE_SMALL, Font.SIZE_MEDIUM, or Font.SIZE_LARGEdrawLabel(int, java.lang.String)
public Turtle addKeyListener(KeyListener keyListener)
public Turtle removeKeyListener()
public Turtle setDelay(int time)
public double towards(double x, double y)
public Turtle home()
public boolean enableRepaint(boolean b)
repaint()
public Turtle repaint()
enableRepaint(boolean)
public Turtle setFillColor(int color)
fillToPoint(double, double)
,
fillToHorizontal(double)
,
fillToVertical(double)
public Turtle setFillColor(int r, int g, int b)
fillToPoint(double, double)
,
fillToHorizontal(double)
,
fillToVertical(double)
public Turtle fillToPoint(double x, double y)
public Turtle fillToHorizontal(double y)
public Turtle fillToVertical(double x)
public Turtle fillOff()
fillToPoint(double, double)
,
fillToHorizontal(double)
,
fillToVertical(double)
public Turtle showPlayground()
public Turtle clone(java.lang.String title)
public Turtle clone()
public Turtle stampTurtle()
public Playground getPlayground()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |