turtle

Module: turtle

Inheritance diagram for pysvg.turtle:

(C) 2008, 2009, 2010 Kerim Mansour For licensing information please refer to license.txt

Classes

Turtle

class pysvg.turtle.Turtle(initialPosition=0.00, 0.00, initialOrientation=1.00, 0.00, fill='white', stroke='black', strokeWidth='1', penDown=False)

Bases: object

Class representing a classical turtle object known from logo and other implementations. Note that currently each turtle has exactly ONE style of drawing, so if you intend to draw in multiple styles several instances of turtles are needed. A turtle will only actually draw when the pen is down (default=false). An xml representation usable for pysvg can ge retrieved using the getXML()-method. To add the turtles paths to an svg you have two opions: Either you simply call “addTurtlePathToSVG” or you can create an svg element and append the Elements of the turtle using a loop, e.g: s=svg(...) t=Turtle(...) for element in t.getSVGElements():

s.addElement(element)
__init__(initialPosition=0.00, 0.00, initialOrientation=1.00, 0.00, fill='white', stroke='black', strokeWidth='1', penDown=False)
Initializes a new Turtle with a new initial position and orientation as well as defaultvalues for style.
addTurtlePathToSVG(svgContainer)
Adds the paths of the turtle to an existing svg container.
backward(distance)
Moves the turtle backwards by distance in the direction it is facing. If the pen is lowered it will also add to the currently drawn polyline.
finish()
MUST be called when drawing is finished. Else the last path will not be added to the stack.
forward(distance)
Moves the turtle forwards by distance in the direction it is facing. If the pen is lowered it will also add to the currently drawn polyline.
getOrientation()
Retrieve current orientation of the turtle.(Vector)
getPosition()
Retrieve current position of the turtle.(Vector)
getSVGElements()
Retrieves the pysvg elements that make up the turtles path and returns them as list.
getXML()
Retrieves the pysvg elements that make up the turtles path and returns them as String in an xml representation.
isPenDown()
Retrieve current status of the pen.(boolean)
left(angle)
Rotates the turtle to the left by angle.
moveTo(vector)
Moves the turtle to the new position. Orientation is kept as it is. If the pen is lowered it will also add to the currently drawn polyline.
penDown()
Lowers the pen down again. A new polyline will be created for drawing. Old polylines will be stored in the stack
penUp()
Raises the pen. Any movement will not draw lines till pen is lowered again.
right(angle)
Rotates the turtle to the right by angle.
setOrientation(vec)
Sets the orientation of the turtle.(Vector)

Vector

class pysvg.turtle.Vector(x, y)

Bases: object

Class representing a vector. Used to determine position of the turtle as well as heading. Also used to calculate movement. Vector class is inspired by tips and code from: - http://slowchop.com/2006/07/15/a-fast-python-vector-class/ - http://www.kokkugia.com/wiki/index.php5?title=Python_vector_class - http://xturtle.rg16.at/code/xturtle.py

__init__(x, y)
Initializes the vector. x and y are coordinates and should be numbers. They will be cast to floats
rotate(angle)
Rotates self counterclockwise by angle (the angle must be given in a 360 degree system)
x
y

Table Of Contents

This Page