-- | Postscript renderer for 'LSystem's.
module LSystem.Render.PS where

import Graphics.PS
import LSystem.LSystem
import LSystem.Turtle

-- | Given initial 'ta', 'ls' and 'll' values render /i/ steps of an
-- 'LSystem'.
renderL :: (LSystem,Double,Double) -> Int -> Double -> [(Pt,Pt)]
renderL (l,ta',ls') i ll' =
    let a = Turtle (radians ta') 1 origin (pi / 2) ll' ls' []
    in render [] (\ll'' p1 p2 -> (p1,p2) : ll'') (expand l i) a

-- | Given a scalar and a 'Path' render a 'greyGS' 'Image'.
draw :: Double -> Path -> Image
draw z p =
    let g = greyGS 0.5
    in (translate 200 200 . scale z z) (Stroke g p)

-- | Rendering functions for grounded (ie. with 'ta' and 'ls' values)
-- 'LSystems'.
renderLL,renderLO :: (LSystem,Double,Double) -> Int -> Double -> Path
renderLL a b = renderLines . renderL a b
renderLO a b = renderLines' . renderL a b