HomeTurtlegraficsGPanelRobotics WebTigerPython |
Python - Online |
Deutsch English |
Start example programs by clicking on links
Turtlegrafics
Modul Import: from gturtle import *
forward(distance), fd(distance) | moves the turtle forwards for given distance |
back(distance), bk(distance) | moves the turtle backwards for given distance |
left(angle), lt(angle) | turns the turtle to the left (in degrees) |
right(angle), rt(angle) | turns the turtle to the right (in degrees) |
hideTurtle(), ht() | hides the turtle |
showTurtle(), st() | shows the turtle |
penDown(), pd() | activates the pen (trace becomes visible) |
penUp(), pu() | deactivates the pen (trace becomes invisible) |
setPenWidth(width) | sets the pen width (in pixels) |
speed(speed) | sets the speed of the turtle movement (1 to 1000, default: 200, -1: no animation) |
delay(time) | stops the program for the given amount of time (in milliseconds) |
distance(x, y) | returns the distance of the turtle to point(x, y) |
getPos() | returns the current position (list) |
getX() | returns the current x-coordinate |
getY() | returns the current y-coordinate |
setPos(x, y) | moves the turtle to the given coordinates without drawing the trace |
setX(x) | sets the turtle to given x-coordinate without drawing the trace |
setY(y) | sets the turtle to given y-coordinate without drawing the trace |
moveTo(x, y) | moves the turtle to the given coordinates by drawing the trace |
heading() | returns the current viewing direction (in degrees, clockwise to the north) |
setHeading(degrees), setH(degrees) | sets the viewing direction (in degrees, zero to the north, positive clockwise) |
towards(x, y) | gives the direction (in degrees) to the position (x, y) |
label(text) | displays text starting at the current turtle position |
clear() | erases the traces and hides the turtle |
clean() | erases the traces but lets the turtle where she is |
clearScreen(), cs() | erases the traces and sets the turtle to the home position |
clear("color") | erases the traces and paints the background with the color (color names: X11-Colors) |
setPenColor(color) | sets the turtle's pen color (color names: X11-Colors) |
setFillColor(color) | sets the turtle's fill color (color names: X11-Colors) |
dot(diameter) | paints a filled circle with given radius using the current pen color |
startPath() | starts to register the turtle movement for a following fill operation |
fillPath() | closes the fill operation at current turtle position and fills the path with the current fill color |
getPixelColorStr() | returns the color as X11 color string of the pixel at the current turtle position (empty, if X11 color name does no exist; None, if outside turtle window) |
without additional import
inputInt(prompt) | opens a modal dialog with OK/Cancel buttons. OK returns integer (the dialog is shown again, if no integer is entered). Cancel or Close terminate the program. The named parameter init sets an initialising value |
inputFloat(prompt) | opens a modal dialog with OK/Cancel buttons. OK returns float (the dialog is shown again, if no float is entered). Cancel or Close terminate the program. The named parameter init sets an initialising value |
input(prompt) | opens a modal dialog with OK/Cancel buttons. OK returns integer, float or string. Cancel or Close terminate the program. The named parameter init sets an initialising value |
import random | imports the module random |
randint(a, b) | returns an integer random number a <= z <= b |
Callbackregistrierung und Turtle-Objekte
makeTurtle() | creates a (global) turtle. A turtle window and a turtle are automatically created in WebTigerPython. |
makeTurtle(mousePressed = onMousePressed) | creates a turtle and registers the callback function onMousePressed, which reacts when a mouse button is pressed |
makeTurtle(mouseDragged = onMouseDragged) | creates a turtle and registers the callback function onMouseDragged, which reacts to the movement with the mouse button pressed |
makeTurtle(keyPressed = onKeyPressed) | creates a turtle and registers the callback function onKeyPressed which reacts to the pressing of a keyboard key |
t = Turtle() | creates a Turtle object. Several Turtle objects can be created, which can be called using the OOP notation. |
Demonstrations
Program | Feature |
Goldstein5.py | Turtlegrafics (forward/right-Paare) |
Peano.py | Fractal |
Spirolateral.py | Recursion |
Mondrian.py | Computer art |
TreeFractal.py | Tree |