public class Turtle
extends java.awt.Canvas
Modifier and Type | Field and Description |
---|---|
boolean |
drawDynamic
If drawDynamic is true you can watch the drawing of the turtle.
|
double |
originX
originX is the x-position of the cartesian coodinate system within the turtle canvas.
|
double |
originY
originY is the y-position of the cartesian coodinate system within the turtle canvas.
|
int |
sleepTime
For drawDynamic = true you set the delay in milliseconds for drawing.
|
double |
turtleW
turtleW is the current angle of the turtle in the range form 0 to 360 degrees.
|
double |
turtleX
turtleX is the x-coordinate of the turtle
Example: myTurtle.turtleX = 100;
|
double |
turtleY
turtleY is the y-coordinate of the turtle.
|
Constructor and Description |
---|
Turtle()
Creates a Turtle with a canvas.
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Clear the Turtle's canvas with the background color.
|
void |
draw(double length)
The Turtle draws a line of the length specified in the current direction.
|
void |
drawto(double x,
double y)
The Turtle draws a line form the current position (turtleX, turtleY) to the
position (x, y) relativ to the cartesian coordinate system.
|
boolean |
isDoubleBuffered() |
void |
move(double length)
The Turtle moves without drawing the length specified in the current
direction.
|
void |
moveto(double x,
double y)
The Turtle moves without drawing to position (x, y) relativ to the
cartesian coordinate system.
|
void |
paint(java.awt.Graphics g)
Shows the Turtle's canvas.
|
void |
setBackground(java.awt.Color c)
Sets the canvas color of the Turtle to color c.
|
void |
setDrawDynamic(boolean b)
Sets DrawDynamic to b.
|
void |
setForeground(java.awt.Color c)
Sets the drawing color of the Turtle to color c.
|
void |
setOrigin(double x,
double y)
Sets the origin of the cartesian coordinate system within the turtle's canvas.
|
void |
setSleepTime(int s)
Sets SleepTime to s.
|
void |
setTurtleW(double w)
Sets turtleW to w.
|
void |
setTurtleX(double x)
Sets turtleX to x.
|
void |
setTurtleY(double y)
Sets turtleY to y.
|
void |
turn(double angle)
Turns the angle of the turtle relativ by the parameter angle.
|
void |
turnto(double angle)
Sets the angle of the turtle absolute by the parameter angle.
|
void |
update(java.awt.Graphics g)
Updates the Turtle's canvas.
|
addNotify, createBufferStrategy, createBufferStrategy, getAccessibleContext, getBufferStrategy
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, dispatchEvent, doLayout, enable, enable, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocusInWindow, reshape, resize, resize, revalidate, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, validate
public double turtleX
Example:
myTurtle.turtleX = 100;
public double turtleY
Example:
myTurtle.turtleY = 200;
public double turtleW
Example:
myTurtle.turtleW = 180;
public double originX
Example:
myTurtle.originX = 0;
public double originY
Example:
myTurtle.originY = 100;
public boolean drawDynamic
Example:
myTurtle.drawDynamic = true;
public int sleepTime
Example:
myTurtle.sleepTime = 500;
public Turtle()
The turtle position can easily be changed by clicking into the canvas.
The size of the canvas can easily be changed with the mouse.
Example:
Turtle myTurtle = new Turtle();
public boolean isDoubleBuffered()
isDoubleBuffered
in class java.awt.Component
public void setTurtleX(double x)
Example:
myTurtle.setTurtleX(100);
public void setTurtleY(double y)
Example:
myTurtle.setTurtleY(-30);
public void setTurtleW(double w)
Example:
myTurtle.setTurtleW(270);
public void setDrawDynamic(boolean b)
Example:
myTurtle.setDrawDynamic(true);
public void setSleepTime(int s)
Example:
myTurtle.setSleepTime(100);
public void turn(double angle)
Example:
myTurtle.turn(-90);
public void turnto(double angle)
Example:
myTurtle.turnto(270);
public void draw(double length)
Example:
myTurtle.draw(100);
public void drawto(double x, double y)
Example:
myTurtle.drawto(200, 300);
public void move(double length)
Example:
myTurtle.move(100);
public void moveto(double x, double y)
Example:
myTurtle.moveto(100, 200);
public void setOrigin(double x, double y)
Example:
myTurtle.setOrigin(100, 200);
public void setForeground(java.awt.Color c)
Example:
myTurtle.setForeground(Color.red);
setForeground
in class java.awt.Component
public void setBackground(java.awt.Color c)
Example:
myTurtle.setBackground(Color.blue);
setBackground
in class java.awt.Component
public void clear()
Example:
myTurtle.clear();
public void paint(java.awt.Graphics g)
paint
in class java.awt.Canvas
public void update(java.awt.Graphics g)
update
in class java.awt.Canvas