Deutsch   English   

Start example programs by clicking on links

Demonstrations

Program Feature
Goldstein5.py Turtlegrafics (forward/right-Paare)
Peano.py Fractal
Spirolateral.py Recursion
Mondrian.py Computer art
TreeFractal.py Tree


Turtlegrafics

Modul Import: from gturtle import *

Command Action
makeTurtle()
defines all global commands and creates a (global) turtle in its window
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
back(distance), bk(distance) moves the turtle backwards for given distance
forward(distance), fd(distance) moves the turtle forwards 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)
penDown(), pd() activates the pen (trace becomes visible)
penUp(), pu() deactivates the pen (trace becomes invisible)
setPenWidth(width) sets the pen width (in pixels)
hideTurtle(), ht() hides the turtle
showTurtle(), st() shows the turtle
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
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)
moveTo(x, y) moves the turtle to the given coordinates by drawing the trace
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


Colors
(Colors are specified as strings, see their names here)
setPenColor(color) sets the turtle's pen color
setFillColor(color) sets the turtle's fill 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)
dot(diameter) paints a filled circle with given radius using the current pen color

 

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