0

I found little information about drawing using the L-system in Elm. There is an L-system library but it is not up do date really, all I have found that could be useful is a turtle graphics library (https://github.com/mrdimosthenis/turtle-graphics) but I am unsure how to draw with it using the L-system. What I have got so far is just a way to generate the nth generation of a sentence from an axiom and a rule:

rule1 : LSystem.Rule State
rule1 state =
    case state of
        A ->
            [ A, B ]

        B ->
            [ A ]


generateNTimes : Int -> (Rule State) -> List State -> List State
generateNTimes n rule axiom = 
    let aux state acc = 
                if n <= 0 
                then state
                else generateNTimes (n - 1) rule ((apply rule state) ++ acc)
    in 
    aux axiom []

I tried drawing using the turtle graphics library I mentioned above, but I am unable to see how I could use it together with the L-system.

hunorg
  • 31
  • 3
  • Probably List.foldl will do the trick lol – hunorg Feb 05 '23 at 21:47
  • 1
    This question is missing the "question" part... What is it you are actually asking about? – Jakub Hampl Feb 06 '23 at 10:30
  • 1
    You need to write a function that interprets a `List State` as a sequence of drawing operations. – molbdnilo Feb 06 '23 at 12:08
  • @JakubHampl you're right, so the question is how should I build up a function that interprets a List State as a sequence of drawing operations?, and would it be a good idea to use the turtle graphics library I mentioned above? The hardest thing for me would be to write the push-current position, push-current angle, pop-current position and pop-current angle commands. – hunorg Feb 06 '23 at 21:53
  • 1
    @hunorg Why is that difficult? That's two stacks, and stacks are simple. – molbdnilo Feb 07 '23 at 14:34

0 Answers0