Turtle Language Reference

This reference is written for people who have prior experience in another programming language. If you are new to programming, you might want to start with the Introduction to Turtle Graphics article.



There are three types of keywords: commands, control flow, and numeric functions.


The turtle will reset in the beginning of each frame.


Changing Color

The turtle uses a custom HDR HSL color space that is designed to make it easy to create pretty color combinations.


The default lightness is 0.


0 = red, 60 = yellow, 120 = green, 180 = cyan, 240 = blue, 300 = magenta, 360 = red. Setting the hue to a value outside of 0..360 will wrap around.

The default hue is 0 (red).


Over-saturated colors: Certain extreme colors are only reachable above 100% saturation – however, hue and lightness will not be accurate. To reach those colors, use set-saturation (it has no maximum) or desaturate with negative values. All sRGB colors are reachable within 200% saturation. Hues that are divisible by 60 stay the same, and other hues will be shifted towards red, green and blue for dark colors, and yellow, cyan and magenta for light colors. Dark colors will become too bright and light colors too deep.

Setting saturation to a negative value is the same as setting it to zero.

The default saturation is 100.


The default opacity is 100 (fully opaque).

Flock Commands

If there are more than 1000 turtles in the flock, random turtles will be removed until there are 1000 left. The same random seed will be used in consecutive frames.

Relative color commands usually yield more pretty results in the flock than absolute commands.



Integers and simple floats are supported. No e-notation. Only decimal base numbers are supported.

Example: forward 10

Example: forward -1.5

Example: forward .5


Any numeric literal value can be replaced with a numeric function in parenthesis.

Example: forward (random 10..100)

Nested example: forward (wave 10..(random 100..200))

Keyword arguments can be supplied with key=value syntax.

Example: forward (wave 10..100 freq=5)

Control Flow

Each block can be ended with end-<name>. For example, repeat blocks are ended with end-repeat.


set-hue -15
repeat 10
    forward (random 0..100)
    turn-left 45
    lighter 7
    hue-shift 5
    lighter (random -3..3)
    hue-shift (random -3..3)
    saturate (random -1..1)
    darker 14
    hue-shift -10
    turn-right 90