Turtle graphics consists of 4 states:
type State
= D -- | Draw forward
| S -- | Skip foward without drawing
| L -- | Turn left by some degrees
| R -- | Turn right by some degrees(In formal literature, it is known as F, f, -, and + respectively.)
Given a starting point and an angle, you can iterate through a list of States
and create a generative drawing.
For example, the following ruleset applied 3 times will generate this:
rule : LSystem.Rule State
rule state =
case state of
D ->
[ D, D, R, D, L, D, R, D, R, D, D ]
S ->
[ S ]
L ->
[ L ]
R ->
[ R ]If you want a complete example of how this can be used in the Elm Architecture, see https://github.com/creative/elm-generative/blob/master/example/Turtle.elm
Transforms a list of States into Svg.Path d-compatible property
strings. This requires a starting point and a starting angle.
You can use the Svg.PathD library's d_
to draw segments as a SVG attribute:
import Svg.PathD as PathD exposing (d_)
...
Svg.path
[ d_ <| turtle [ D, R, D, R, D, R, D ] 90
]
[]
Turtle consists of 4 primary states.
We also supply additional states
A,B, andC, which are ignored during drawing. They are useful for constructing rulesets only.