cga/Diagram.hs

34 lines
1010 B
Haskell

module Diagram where
import Diagrams.Prelude
import Diagrams.Backend.Cairo
import Meshparser
import Util
-- |Holds the properties for a Diagram, like thickness of 2d points etc.
data DiagProp = MkProp {
-- |Get the thickness of the dot.
getThickness :: Double
}
-- |Create the Diagram from the VTable.
diagFromVTable :: DiagProp -> VTable -> Diagram Cairo R2
diagFromVTable prop vt
= position (zip (map mkPoint . filter (inRange 0 500) $ vt)
(repeat dot)) # moveTo (p2(-250, -250))
`atop` hrule 500 # centerX # moveTo (p2(0, -250))
`atop` vrule 500 # centerY # moveTo (p2(-250, 0))
`atop` square 550 # lwG 0.00 # bg white
where dot = (circle $
getThickness prop :: Diagram Cairo R2) # fc black
mkPoint (x,y) = p2 (x,y)
-- |Create the Diagram from a String.
diagFromString :: DiagProp -> String -> Diagram Cairo R2
diagFromString prop mesh
= diagFromVTable prop .
meshToArr $
mesh