diagrams-contrib-1.4.4: Collection of user contributions to diagrams EDSL

Diagrams.TwoD.Path.LSystem

Description

Create LSystem diagrams and paths.

See "The Algorithmic Beauty of Plants". http://algorithmicbotany.org/papers/abop/abop-ch1.pdf

Synopsis

# Lindenmayer Systems

## L-Systems

data Symbol n Source #

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.

Constructors

 F G Plus Minus Reverse Flip Push Pop X Int Width n Delta n
Instances
 Eq n => Eq (Symbol n) Source # Instance detailsDefined in Diagrams.TwoD.Path.LSystem Methods(==) :: Symbol n -> Symbol n -> Bool #(/=) :: Symbol n -> Symbol n -> Bool # Ord n => Ord (Symbol n) Source # Instance detailsDefined in Diagrams.TwoD.Path.LSystem Methodscompare :: Symbol n -> Symbol n -> Ordering #(<) :: Symbol n -> Symbol n -> Bool #(<=) :: Symbol n -> Symbol n -> Bool #(>) :: Symbol n -> Symbol n -> Bool #(>=) :: Symbol n -> Symbol n -> Bool #max :: Symbol n -> Symbol n -> Symbol n #min :: Symbol n -> Symbol n -> Symbol n # Show n => Show (Symbol n) Source # Instance detailsDefined in Diagrams.TwoD.Path.LSystem MethodsshowsPrec :: Int -> Symbol n -> ShowS #show :: Symbol n -> String #showList :: [Symbol n] -> ShowS #

type Rules n = Map (Symbol n) [Symbol n] Source #

Production rules.

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

rule :: Fractional n => Char -> String -> (Symbol n, [Symbol n]) Source #

# Predefined L-Systems

Sierpinski triangle. cantor :: (Renderable (Path V2 n) b, TypeableFloat n) => Int -> QDiagram b V2 n Any Source #

Cantor dust dragon :: RealFloat n => Int -> TurtleState n Source #

Dragon curve Hexagonal Gosper curve Koch Island Koch lake koch1 :: RealFloat n => Int -> TurtleState n Source #

Koch curve 1 koch2 :: RealFloat n => Int -> TurtleState n Source #

Koch curve 2 koch3 :: RealFloat n => Int -> TurtleState n Source #

Koch curve 3 koch4 :: RealFloat n => Int -> TurtleState n Source #

Koch curve 4 koch5 :: RealFloat n => Int -> TurtleState n Source #

Koch curve 5 koch6 :: RealFloat n => Int -> TurtleState n Source #

Koch curve 6 tree1 :: RealFloat n => Int -> TurtleState n Source #

Tree 1 tree2 :: RealFloat n => Int -> TurtleState n Source #

Tree 2 tree3 :: RealFloat n => Int -> TurtleState n Source #

Tree 3 tree4 :: RealFloat n => Int -> TurtleState n Source #

Tree 4 tree5 :: RealFloat n => Int -> TurtleState n Source #

Tree 5 tree6 :: RealFloat n => Int -> TurtleState n Source #

Tree 6 # 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