# (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.

**current-turtle**    <img src="/files/mK8eMQUj1oS8rq8TeU89" alt="" data-size="line">

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`.

**(turtle?&#x20;*****obj*****)** <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">

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

**(make-turtle&#x20;*****x y scale*****)** <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">

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.

**(turtle-drawing&#x20;*****turtle*****)** <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">

Returns the drawing associated with the given *turtle*.

**(turtle-x&#x20;*****turtle*****)** <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">

Returns the x coordinate of the position of the given *turtle*.

**(turtle-y&#x20;*****turtle*****)** <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">

Returns the y coordinate of the position of the given *turtle*.

**(turtle-angle&#x20;*****turtle*****)** <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">

Returns the current angle of the given *turtle*.

**(turtle-angle&#x20;*****turtle*****)** <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">

Returns the current angle of the given *turtle*.

**(turtle-pen-down?&#x20;*****turtle*****)** <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">

Returns `#t` if the given *turtle* has its pen down; otherwise `#f` is returned.

**(pen-up)** <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">\
\&#xNAN;**(pen-up&#x20;*****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.

**(pen-down)** <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">\
\&#xNAN;**(pen-down&#x20;*****turtle*****)**

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.

**(pen-color&#x20;*****color*****)** <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">\
\&#xNAN;**(pen-color&#x20;*****color turtle*****)**

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)`.

**(pen-size&#x20;*****size*****)** <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">\
\&#xNAN;**(pen-size&#x20;*****size turtle*****)**

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`.

**(home)** <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">\
\&#xNAN;**(home&#x20;*****turtle*****)**

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

**(move&#x20;*****x y*****)** <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">\
\&#xNAN;**(move&#x20;*****x y turtle*****)**

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.

**(heading&#x20;*****angle*****)** <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">\
\&#xNAN;**(heading&#x20;*****angle turtle*****)**

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.

**(turn&#x20;*****angle*****)** <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">\
\&#xNAN;**(turn&#x20;*****angle turtle*****)**

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

**(right&#x20;*****angle*****)** <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">\
\&#xNAN;**(right&#x20;*****angle turtle*****)**

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

**(left&#x20;*****angle*****)** <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">\
\&#xNAN;**(left&#x20;*****angle turtle*****)**

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

**(forward&#x20;*****distance*****)** <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">\
\&#xNAN;**(forward&#x20;*****distance turtle*****)**

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.

**(backward&#x20;*****distance*****)** <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">\
\&#xNAN;**(backward&#x20;*****distance turtle*****)**

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.

**(arc&#x20;*****angle radius*****)** <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">\
\&#xNAN;**(arc&#x20;*****angle radius turtle*****)**

Turns the turtle by the given *angle* (in radians) and draws an arc with *radius* around the current turtle position if the pen is down. If *turtle* is not provided, the turtle defined by `current-turtle` is used.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://www.lisppad.app/libraries/lispkit/lispkit-draw-turtle.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
