Turtle

Position

A position on the canvas.

Turtle

A turtle that can move around the canvas and draw lines.

new : { position ? Position, direction ? F64, pen ? [ Up, Down ] } -> Turtle

Create a new turtle at the origin facing right with the pen down.

getPosition : Turtle -> Position

Get the turtle's current position.

forward : Turtle, F64 -> Turtle

Move the turtle forward by a distance.

moveTo : Turtle, Position -> Turtle

Move the turtle to a new position without changing its direction.

getDirection : Turtle -> F64

Get the turtle's current direction.

turn : Turtle, F64 -> Turtle

Turn the turtle by an angle.

turnTo : Turtle, F64 -> Turtle

Turn the turtle to an absolute angle.

pointAt : Turtle, Position -> Turtle

Point the turtle at a position.

getPen : Turtle -> [ Up, Down ]

Get the pens' current state.

setPen : Turtle, [ Up, Down, Invert ] -> Turtle

Set the pen to Up, Down, or Invert (toggle between Up and Down)

getLines : Turtle -> List (List Position)

Get all the lines drawn by the turtle so far.

repeat : Turtle, U64, (Turtle -> Turtle) -> Turtle

Repeat a function n times

toSvg : Turtle, { x : { from : F64, to : F64 }, y : { from : F64, to : F64 }, scale ? F64 } -> Str

Convert the turtle's lines to an SVG string