47. turtle — Turtle graphics for pyFormex — pyFormex v0.8.6 documentation

### Navigation

- index
- modules |
- next |
- previous |
- pyFormex v0.8.6 documentation >
- pyFormex reference manual >

# 47. `turtle` — Turtle graphics for pyFormex

This module was mainly aimed at the drawing of Lindenmayer products (see `plugins.lima` and the Lima example).

The idea is that a turtle can be moved in 2D from one position to another, thereby creating a line between start and endpoint or not.

The current state of the turtle is defined by

- `pos`: the position as a 2D coordinate pair (x,y),
- `angle`: the moving direction as an angle (in degrees) with the x-axis,
- `step`: the speed, as a discrete step size.

The start conditions are: `pos=(0,0), step=1., angle=0.`

The followin example turtle script creates a unit square:

    fd();ro(90);fd();ro(90);fd();ro(90);fd()

`Classes defined in module turtle`

`Functions defined in module turtle`

`turtle.` `sind`(arg)

  Return the sine of an angle in degrees.

`turtle.` `cosd`(arg)

  Return the cosine of an angle in degrees.

`turtle.` `reset`()

  Reset the turtle graphics engine to start conditions.

  This resets the turtle’s state to the starting conditions `pos=(0,0), step=1., angle=0.`, removes everything from the state save stack and empties the resulting path.

`turtle.` `push`()

  Save the current state of the turtle.

  The turtle state includes its position, step and angle.

`turtle.` `pop`()

  Restore the turtle state to the last saved state.

`turtle.` `fd`(d=None, connect=True)

  Move forward over a step d, with or without drawing.

  The direction is the current direction. If d is not given, the step size is the current step.

  By default, the new position is connected to the previous with a straight line segment.

`turtle.` `mv`(d=None)

  Move over step d without drawing.

`turtle.` `ro`(a)

  Rotate over angle a. The new direction is incremented with a

`turtle.` `go`(p)

  Go to position p (without drawing).

  While the mv method performs a relative move, this is an absolute move. p is a tuple of (x,y) values.

`turtle.` `st`(d)

  Set the step size.

`turtle.` `an`(a)

  Set the angle

`turtle.` `play`(scr, glob=None)

  Play all the commands in the script scr

  The script is a string of turtle commands, where each command is ended with a semicolon (‘;’).

  If a dict glob is specified, it will be update with the turtle module’s globals() after each turtle command.

### Navigation

- index
- modules |
- next |
- previous |
- pyFormex v0.8.6 documentation >
- pyFormex reference manual >