(lispkit draw turtle)

Library (lispkit draw turtle) defines a simple "turtle graphics" API. The API provides functionality for creating turtles and for moving turtles on a plane generating drawings as a side-effect. A drawing is a data structure defined by library (lispkit draw).

A turtle is defined in terms of the following components:

  • A position (x, y) defining the coordinates where the turtle is currently located within a coordinate system defined by parameters used to create the turtle via make-turtle

  • A heading angle which defines the direction in degrees into which the turtle is moving

  • A boolean flag pen down which, if set to #t, will make the turtle draw lines on the graphics plane when moving.

  • A line width defining the width of lines drawn by the turtle

  • A color defining the color of lines drawn by the turtle

  • A drawing which records the moves of the turtle while the pen is down.

Turtles are mutable objects created via make-turtle. The functions listed below change the state of a turtle. In particular, they generate a drawing as a side-effect which can be accessed via turtle-drawing. For most functions, the turtle is an optional argument. If it is not provided, the function applies to the turtle provided by the current-turtle parammeter object.


Defines the current turtle, which is used as a default by all functions for which the turtle argument is optional. If there is no current turtle, this parameter is set to #f.

Returns #t if obj is a turtle. Otherwise, it returns #f.

Returns a new turtle object. x and y determine the "home point" of the turtle. This is equivalent to the zero point of the coordinate system in which the turtle navigates. scale is a scaling factor.

Returns the drawing associated with the given turtle.

Lifts turtle from the plane. If turtle is not provided, the turtle defined by current-turtle is used. Subsequent forward and backward operations don't lead to lines being drawn. Only the current coordinates are getting updated.

Drops turtle onto the plane. If turtle is not provided, the turtle defined by current-turtle is used. Subsequent forward and backward operations will lead to lines being drawn.

Sets the drawing color of turtle to color. If turtle is not provided, the turtle defined by current-turtle is used. color is a color object as defined by library (lispkit draw).

Sets the pen size of turtle to size. If turtle is not provided, the turtle defined by current-turtle is used. The pen size corresponds to the width of lines drawn by forward and backward.

Moves turtle to its home position. If turtle is not provided, the turtle defined by current-turtle is used.

Moves turtle to the position described by the coordinates x and y. If turtle is not provided, the turtle defined by current-turtle is used.

Sets the heading of turtle to angle. If turtle is not provided, the turtle defined by current-turtle is used. angle is expressed in terms of degrees.

Adjusts the heading of turtle by angle degrees. If turtle is not provided, the turtle defined by current-turtle is used.

Adjusts the heading of turtle by angle degrees. If turtle is not provided, the turtle defined by current-turtle is used.

Adjusts the heading of turtle by -angle degrees. If turtle is not provided, the turtle defined by current-turtle is used.

Moves turtle forward by distance units drawing a line if the pen is down. If turtle is not provided, the turtle defined by current-turtle is used.

Moves turtle backward by distance units drawing a line if the pen is down. If turtle is not provided, the turtle defined by current-turtle is used.

Last updated