Stream: show and tell

Topic: A turtle library


view this post on Zulip Hannes (Nov 30 2024 at 02:08):

A while ago Oskar Hahn shared the roc-turtle platform. I wanted to try making a turtle library that would let you use pipe the turtle value through pure functions and then output the final path as an image.

I created the roc-turtle library, and used roc-svg to convert the path to an SVG string.

Here's an example from the readme:

import turtle.Turtle

Create a Turtle using the Turtle.new function.

turtle = Turtle.new {}

Use functions like Turtle.forward and Turtle.turn to move the turtle.

path = turtle |> Turtle.forward 1 |> Turtle.turn (Num.pi / 4)

When your drawing is done, use the Turtle.toSvg function to convert it into an SVG string which you can output to a file.

svgStr = Turtle.toSvg path { x: { from: -500, to: 500 }, y: { from: -500, to: 500 } }

Last updated: Jul 06 2025 at 12:14 UTC