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.
//
starts a comment. The rest of the line is ignored by the parser.There are three types of keywords: commands, control flow, and numeric functions.
The turtle will reset in the beginning of each frame.
forward <distance>
- move forward by the given number of scaled pixels (the shorter side of the canvas is always 1000 units).backward <distance>
- move backward. Does not draw a line even if the pen is down.move-left <distance>
- move left. Does not draw a line even if the pen is down. Does not rotate the turtle.move-right <distance>
- move right.turn-left <degrees>
- change the turtle's heading.turn-right <degrees>
- change the turtle's heading.arc-left
and arc-right
draw a circle arc. They have 3 parameters, out of which any 2 must be specified:angle=<degrees>
- the angle of the arc in degreesradius=<distance>
- the distance from the pivot pointlength=<distance>
- the length of the path along the diameter of the circle.circle <radius>
- draw a circle.text "<text>"
- draw text at the turtle's position. "
are not yet allowed, but ”
can be used instead.pen-up
- the turtle will not draw a line when moving.pen-down
- the turtle will draw a line when moving.bigger <percent>
- makes the line thicker and movements scaled. Multiplier is 1 + percent / 100.smaller <percent>
- makes the line thinner and movements scaled. Multiplier is 1 / (1 + percent / 100).set-thickness
- set the thickness of the turtle's line. Units are the same as travel distances.fill-canvas
- fill the entire canvas with the turtle's color.The turtle uses a custom HDR HSL color space that is designed to make it easy to create pretty color combinations.
set-lightness <lightness>
- set the lightness of the turtle's color. This uses a HDR color space. 0 means gray, negative values are darker, positive values are lighter. 10 units is equal to one stop of exposure in a DSLR camera. Most usable colors are between -50 and 50. Normal 8-bit displays can't display darker than about -100 or brighter than about +100.darker <amount>
- make the turtle's color darker by the given amount.lighter <amount>
- make the turtle's color lighter by the given amount.The default lightness is 0.
set-hue <hue>
- set the hue of the turtle's color. The hue is a number between 0 and 360 - same as the hue in HSL color space.hue-shift <degrees>
- change the hue of the turtle's color relative to the current color.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).
set-saturation <saturation>
- set the saturation of the turtle's color. 100 means full saturation and 0 means gray.saturate <amount>
- make the turtle's color more saturated by the given amount. Can't go above 100.desaturate <amount>
- make the turtle's color less saturated by the given amount.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.
set-opacity <alpha>
- set the opacity of the turtle's color. 0 means fully transparent and 100 means fully opaque.The default opacity is 100 (fully opaque).
Flock commands can be used to create fractals.
mirror
- creates a copy of the turtle(s) with left and right reversed.lay-egg
- each turtle (initially 1) makes a frozen copy of itself. The eggs do not do anything before they are hatched. This command can be called multiple times before hatching.hatch-eggs
- add all eggs to the flock. After that, all turtles respond to commands. If there are no eggs, this command does nothing.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)
wave <min>..<max>
- returns a sine wave between min and max. Currently only 20 cycles per minute is supported, and there is no phase setting.frequency
, freq
, f
- the number of cycles per minute. Default is 20.phase
, p
- the phase of the wave in cycles (0..100). Default is 0.linear <min>..<max>
- returns a value that linearly increases from min to max, then jumps back to min. A sawtooth wave. sawtooth
is an alias of this function.frequency
, freq
, f
- see wave
.phase
, p
- see wave
.noise <min>..<max>
- returns a semi-random float between min and max. Turtles that are close to each other will get similar values. The value varies smoothly over time.frequency
, freq
, f
- see wave
.phase
, p
- see wave
, except phase can be larger than 100 or smaller than 0.size
, s
- the size of the noise. Default is 300.random <min>..<max>
- returns a random float between min and max. In the flock, each turtle will get a different random number. Consecutive frames will have the same random seed.skew
, s
- the underlying random t=0..1 value will become pow(t, exp(-skew / 100)). Default is 0 (uniform distribution). Negative values will skew towards min, positive values will skew towards max.repeat <count>
- start a block that will be repeated the given number of times.side-track
- when the block ends, the turtle flock will be restored to the exact state it was in when the block started.fill
– turtle will fill a closed shape with its color at the end of the block. The shape is defined by the commands inside the fill
block.set-clip
– similar to fill, but the shape is used as a clipping mask instead of being filled. The shape is defined by the commands inside the set-clip
block. Can be removed with unset-clip
.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)
lay-egg
darker 14
hue-shift -10
turn-right 90
hatch-eggs
end-repeat