WorldTurtle is a Haskell take on Turtle Graphics.
The intent of this module is a teaching tool by using turtle commands to produce animations.
Turtle commands are monads!
The following snippet produces a square:
import Graphics.WorldTurtle
main :: IO ()
main = runTurtle $
repeatFor 4 $ do
forward 90
right 90Like so!
Use of the parallel animation operator (>!>) allows animations to run in
parallel. The
parallel/serial comparison
example shows that when given this code:
import Graphics.WorldTurtle
main :: IO ()
main = runWorld $ do
turtle1 <- makeTurtle' (0, 0) north green
turtle2 <- makeTurtle' (0, 0) north red
-- Draw the anticlockwise and clockwise circles in sequence.
(turtle1 >/> circle 90) >> (turtle2 >/> circle (-90))
clear
-- Draw the anticlockwise and clockwise circles in parallel.
(turtle1 >/> circle 90) >!> (turtle2 >/> circle (-90))We get this animation:
You can interact with the animation window in the following ways:
| Action | Interaction |
|---|---|
| Pan the viewport. | Click and drag |
| Zoom in/out. | Mousewheel up/down |
| Reset the viewport to initial position. | Spacebar |
| Reset the animation. | R key |
| Pause the animation. | P key |
| Quit | Escape key |
For all examples, look here!
spiralstar example
spiralsquare example
lsystem example
To build this project you need stack and ghc. If you don't
already have these, then you can install them easily from the
Haskell Platform!
If you get this error on startup:
user error (unknown GLUT entry glutInit)
Then this means you need the freeglut MSVC binaries which you can get
here.
Extract freeglut\bin\x64\freeglut.dll to the same location as the executable
you wish to run, or place it in a folder that can be discovered by your %PATH% variable.
(Here are some steps on how to add a new folder to your %PATH%.)
Using stack, you can create your own worldturtle project by using the provided
template.
To create and run your own project, use the following commands to get setup:
stack new my-new-project aneilmac/worldturtle
cd my-new-project
stack build
stack exec my-new-projectExamples can be built via stack.
stack setup
stack buildAfter building, examples in the worldturtle-examples folder can then be
executed from stack. To run parallelcircles try:
stack exec parallelcircles-exeSee here for a detailed description on porting LOGO code to WorldTurtle.





