hls-0.15: Haskell Lindenmayer Systems

Safe HaskellSafe-Inferred
LanguageHaskell98

LSystem.LSystem

Description

Lindenmayer system definition, expander and renderer.

Synopsis

Documentation

type Element = Char Source

Element of Axiom.

type Axiom = [Element] Source

An axiom (sequence of Elements).

data LSystem Source

An LSystem is an Axiom and a set of Rules.

Constructors

LSystem Axiom Rules 

Instances

lSystem :: Axiom -> [(Element, [Element])] -> LSystem Source

L-System constructor.

lSystem "F+F+F" [('F',"F-F+F")]

getRule :: Rules -> Element -> [Element] Source

Rule lookup.

applyRule :: [Element] -> Rules -> [Element] Source

Rule application.

expand :: LSystem -> Int -> [Element] Source

n iterations of the specified LSystem.

let f p q n = expand (lSystem p q) n
f  "A" [('A',"AB"),('B',"A")] 5 == "ABAABABAABAAB"
f "0" [('1',"11"),('0',"1[0]0")] 3 == "1111[11[1[0]0]1[0]0]11[1[0]0]1[0]0"
f  "A" [('A',"ABA"),('B',"BBB")] 3 == "ABABBBABABBBBBBBBBABABBBABA"
f  "F" [('F',"F+F-F-F+F")] 2 == "F+F-F-F+F+F+F-F-F+F-F+F-F-F+F-F+F-F-F+F+F+F-F-F+F"
f "F+F+F" [('F',"F-F+F")] 1 == "F-F+F+F-F+F+F-F+F"

stateT :: Element -> Turtle -> Turtle Source

State transformer Turtle commands.

cmd :: (Turtle -> b -> (Turtle, b)) -> Element -> Turtle -> b -> (Turtle, b) Source

Operational Turtle commands.

render :: b -> (b -> Pt R -> Pt R -> b) -> [Element] -> Turtle -> b Source

Fold over an expanded L-system using standard turtle commands.