Copyright | (c) 2015 Jeffrey Rosenbluth |
---|---|
License | BSD-style (see LICENSE) |
Maintainer | jeffrey.rosenbluth@gmail.com |
Safe Haskell | None |
Language | Haskell2010 |
Create LSystem diagrams and paths.
See "The Algorithmic Beauty of Plants". http://algorithmicbotany.org/papers/abop/abop-ch1.pdf
- data Symbol n
- type Rules n = Map (Symbol n) [Symbol n]
- generations :: Ord n => Rules n -> [Symbol n] -> [[Symbol n]]
- lSystemR :: (Floating n, Ord n) => [Symbol n] -> Reader (Environment n) (TurtleState n)
- lSystem :: (Floating n, Ord n) => Int -> Angle n -> [Symbol n] -> Rules n -> TurtleState n
- lSystemPath :: (Floating n, Ord n) => Int -> Angle n -> [Symbol n] -> Rules n -> Path V2 n
- lSystemDiagram :: (TypeableFloat n, Renderable (Path V2 n) b) => Int -> Angle n -> [Symbol n] -> Rules n -> QDiagram b V2 n Any
- symbol :: Fractional n => Char -> Symbol n
- symbols :: Fractional n => String -> [Symbol n]
- rule :: Fractional n => Char -> String -> (Symbol n, [Symbol n])
- sierpinski :: RealFloat n => Int -> TurtleState n
- cantor :: (Renderable (Path V2 n) b, TypeableFloat n) => Int -> QDiagram b V2 n Any
- dragon :: RealFloat n => Int -> TurtleState n
- hexGosper :: RealFloat n => Int -> TurtleState n
- kochIsland :: RealFloat n => Int -> TurtleState n
- kochLake :: RealFloat n => Int -> TurtleState n
- koch1 :: RealFloat n => Int -> TurtleState n
- koch2 :: RealFloat n => Int -> TurtleState n
- koch3 :: RealFloat n => Int -> TurtleState n
- koch4 :: RealFloat n => Int -> TurtleState n
- koch5 :: RealFloat n => Int -> TurtleState n
- koch6 :: RealFloat n => Int -> TurtleState n
- tree1 :: RealFloat n => Int -> TurtleState n
- tree2 :: RealFloat n => Int -> TurtleState n
- tree3 :: RealFloat n => Int -> TurtleState n
- tree4 :: RealFloat n => Int -> TurtleState n
- tree5 :: RealFloat n => Int -> TurtleState n
- tree6 :: RealFloat n => Int -> TurtleState n
- data TurtleState n
- getTurtlePath :: (Floating n, Ord n) => TurtleState n -> Path V2 n
- getTurtleDiagram :: (Renderable (Path V2 n) b, TypeableFloat n) => TurtleState n -> QDiagram b V2 n Any
Lindenmayer Systems
L-Systems
Symbols:
F ('F') draw a segment.
G ('f' or 'G') move the turtle one unit without drawing anything.
Plus ('+') turn the turtle clockwise.
Minus ('-') turn the turtle anti-clockwise.
Reverse ('!') turn the turtle 180 degrees.
Flip ('~') switch right and left.
Push ('[') push the current state onto the stack.
Pop (']') pop the current state.
Width x ('<', '>') increase (decrease) stroke width by factor of 1.1 (0.9).
Delta x ('(', ')') increase (decrease) turn angle by factor of 1.1 (0.9).
X n ('X','Y','Z','A','B') constants.
generations :: Ord n => Rules n -> [Symbol n] -> [[Symbol n]] Source #
Successive generations of the production rules applied to the starting symbols.
L-System graphics
lSystemR :: (Floating n, Ord n) => [Symbol n] -> Reader (Environment n) (TurtleState n) Source #
Interpret a list of symbols as turtle graphics commands
to create a TurtleState
. The turtle data is tracked in a Reader monad.
lSystem :: (Floating n, Ord n) => Int -> Angle n -> [Symbol n] -> Rules n -> TurtleState n Source #
Create a TurtelState
using n iterations of the rules with given axiom symbols
and the angle increment, delta. The first segment is in the unitX direction.
lSystemPath :: (Floating n, Ord n) => Int -> Angle n -> [Symbol n] -> Rules n -> Path V2 n Source #
Create a path using n iterations of the rules with given axiom symbols
and the angle increment, delta. The first segment is in the unitX direction.
The styles in the TurtleState
are ignored.
lSystemDiagram :: (TypeableFloat n, Renderable (Path V2 n) b) => Int -> Angle n -> [Symbol n] -> Rules n -> QDiagram b V2 n Any Source #
Create a diagram using n iterations of the rules with given axiom symbols
and the angle increment, delta. The first segment is in the unitX direction.
The styles in the TurtleState
are applied to the trails in the diagram.
Making rules from strings
Predefined L-Systems
sierpinski :: RealFloat n => Int -> TurtleState n Source #
Sierpinski triangle.
cantor :: (Renderable (Path V2 n) b, TypeableFloat n) => Int -> QDiagram b V2 n Any Source #
Cantor dust
kochIsland :: RealFloat n => Int -> TurtleState n Source #
Koch Island
Re-exports from Diagrams.TwoD.Path.Turtle
data TurtleState n Source #
Core turtle data type. A turtle needs to keep track of its current position, like its position, heading etc., and all the paths that it has traversed so far.
We need to record a new path, everytime an attribute like style, pen position etc changes, so that we can separately track styles for each portion of the eventual path that the turtle took.
getTurtlePath :: (Floating n, Ord n) => TurtleState n -> Path V2 n Source #
Creates a path from a turtle, ignoring the styles.
getTurtleDiagram :: (Renderable (Path V2 n) b, TypeableFloat n) => TurtleState n -> QDiagram b V2 n Any Source #
Creates a diagram from a turtle
Applies the styles to each trails in paths
separately and combines them
into a single diagram