wumpus-microprint 0.3.0 → 0.4.0
raw patch · 7 files changed
+96/−34 lines, 7 filesdep ~wumpus-basicPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: wumpus-basic
API changes (from Hackage documentation)
- Wumpus.MicroPrint.DrawMonad: LineBreak :: Tile
- Wumpus.MicroPrint.DrawMonad: Space :: Int -> Tile
- Wumpus.MicroPrint.DrawMonad: Word :: DRGB -> Int -> Tile
- Wumpus.MicroPrint.DrawMonad: char :: MicroPrint ()
- Wumpus.MicroPrint.DrawMonad: data MicroPrint a
- Wumpus.MicroPrint.DrawMonad: data Tile
- Wumpus.MicroPrint.DrawMonad: execMicroPrint :: MicroPrint a -> ([Tile], Height)
- Wumpus.MicroPrint.DrawMonad: instance Functor MicroPrint
- Wumpus.MicroPrint.DrawMonad: instance Monad MicroPrint
- Wumpus.MicroPrint.DrawMonad: linebreak :: MicroPrint ()
- Wumpus.MicroPrint.DrawMonad: runMicroPrint :: MicroPrint a -> (a, [Tile], Height)
- Wumpus.MicroPrint.DrawMonad: setRGB :: DRGB -> MicroPrint ()
- Wumpus.MicroPrint.DrawMonad: space :: MicroPrint ()
- Wumpus.MicroPrint.DrawMonad: type Height = Int
- Wumpus.MicroPrint.Render: MP_config :: Double -> Double -> Double -> DrawF -> MP_config
- Wumpus.MicroPrint.Render: borderedF :: Double -> DrawF
- Wumpus.MicroPrint.Render: char_height :: MP_config -> Double
- Wumpus.MicroPrint.Render: char_width :: MP_config -> Double
- Wumpus.MicroPrint.Render: data MP_config
- Wumpus.MicroPrint.Render: drawF :: MP_config -> DrawF
- Wumpus.MicroPrint.Render: drawMicroPrint :: MP_config -> ([Tile], Height) -> Maybe DPicture
- Wumpus.MicroPrint.Render: greekF :: DrawF
- Wumpus.MicroPrint.Render: instance Applicative RenderMonad
- Wumpus.MicroPrint.Render: instance Functor RenderMonad
- Wumpus.MicroPrint.Render: instance Monad RenderMonad
- Wumpus.MicroPrint.Render: instance ReaderM RenderMonad MP_config
- Wumpus.MicroPrint.Render: instance TraceM RenderMonad DPrimitive
- Wumpus.MicroPrint.Render: instance TurtleM RenderMonad
- Wumpus.MicroPrint.Render: line_spacing :: MP_config -> Double
- Wumpus.MicroPrint.Render: type DrawF = (Int, Double) -> (Double, Double) -> DRGB -> DGraphicF
+ Wumpus.MicroPrint: MicroPrintConfig :: Double -> Double -> Double -> DrawWordF -> MicroPrintConfig
+ Wumpus.MicroPrint: borderedF :: Double -> DrawWordF
+ Wumpus.MicroPrint: char_height :: MicroPrintConfig -> Double
+ Wumpus.MicroPrint: char_width :: MicroPrintConfig -> Double
+ Wumpus.MicroPrint: data MicroPrintConfig
+ Wumpus.MicroPrint: drawMicroPrint :: MicroPrintConfig -> ([Tile], Height) -> Maybe DPicture
+ Wumpus.MicroPrint: drawWordF :: MicroPrintConfig -> DrawWordF
+ Wumpus.MicroPrint: greekF :: DrawWordF
+ Wumpus.MicroPrint: line_spacing :: MicroPrintConfig -> Double
+ Wumpus.MicroPrint: renderMicroPrintU :: MicroPrintConfig -> MicroPrint a -> DPicture
+ Wumpus.MicroPrint: type DrawWordF = (Int, Double) -> (Double, Double) -> DRGB -> DGraphicF
- Wumpus.MicroPrint: renderMicroPrint :: MP_config -> MicroPrint a -> Maybe DPicture
+ Wumpus.MicroPrint: renderMicroPrint :: MicroPrintConfig -> MicroPrint a -> Maybe DPicture
Files
- CHANGES +11/−0
- demo/Demo01.hs +3/−3
- src/Wumpus/MicroPrint.hs +18/−3
- src/Wumpus/MicroPrint/DrawMonad.hs +20/−5
- src/Wumpus/MicroPrint/Render.hs +28/−17
- src/Wumpus/MicroPrint/VersionNumber.hs +2/−2
- wumpus-microprint.cabal +14/−4
CHANGES view
@@ -1,4 +1,15 @@ +0.3.0 to 0.4.0:++ * Implementation modules are now hidden. Added some documentation.++ * DrawF renamed DrawWordF, MP_config renamed MicroPrintConfig.+ +0.2.0 to 0.3.0:++ * Updated to use ConsDrawing monad from Wumpus-Basic.++ 0.1.1 to 0.2.0: * Updated to use Basic.Graphic types from wumpus-basic-0.2.0.
demo/Demo01.hs view
@@ -38,12 +38,12 @@ drawChar _ = char -cfg1 :: MP_config-cfg1 = MP_config +cfg1 :: MicroPrintConfig+cfg1 = MicroPrintConfig { char_height = 12.0 , char_width = 8.0 , line_spacing = 3.0- , drawF = borderedF 1.0+ , drawWordF = borderedF 1.0 }
src/Wumpus/MicroPrint.hs view
@@ -20,8 +20,9 @@ -- * Re-export all MicroPrint.Render module Wumpus.MicroPrint.Render - -- * Top level rendering function+ -- * Top level rendering functions , renderMicroPrint+ , renderMicroPrintU -- * Re-export some from MicroPrint.DrawMonad , MicroPrint@@ -34,14 +35,28 @@ ) where -import Wumpus.Core import Wumpus.MicroPrint.DrawMonad import Wumpus.MicroPrint.Render +import Wumpus.Core -- package: wumpus-core +import Data.Maybe + -- | Build a picture from a MicroPrint. ---renderMicroPrint :: MP_config -> MicroPrint a -> Maybe DPicture+-- This function returns Nothing if the picture is empty.+-- +renderMicroPrint :: MicroPrintConfig -> MicroPrint a -> Maybe DPicture renderMicroPrint cfg mf = drawMicroPrint cfg $ execMicroPrint mf+++-- | Build a picture from a MicroPrint - /unsafe/ version.+--+-- This function throws a runtime error if the picture is empty.+-- +renderMicroPrintU :: MicroPrintConfig -> MicroPrint a -> DPicture+renderMicroPrintU cfg mf = fromMaybe errK $ renderMicroPrint cfg mf+ where+ errK = error "renderMicroPrintU - empty picture."
src/Wumpus/MicroPrint/DrawMonad.hs view
@@ -10,7 +10,9 @@ -- Stability : unstable -- Portability : GHC ----- MicroPrints drawing monad +-- MicroPrints drawing monad - drawing here is analogous to a +-- /teletype/ drawing characters, spaces and linebreaks one at a +-- time. -- -------------------------------------------------------------------------------- @@ -49,8 +51,11 @@ type Height = Int type State = (TileState, DRGB, Height) --- | A /microprint/ is really a monad in disguise...+-- | Build a /microprint/ within a monad... --+-- Drawings are made in a /teletype/ fashion emitting a character,+-- space or line-break at each step.+-- newtype MicroPrint a = MicroPrint { getMicroPrint :: Trace -> State -> (a,Trace,State) } @@ -83,21 +88,30 @@ step rgb (W0 n) = (\f -> f `snocH` (Word rgb n)) +-- | Emit a linebreak in the output.+-- linebreak :: MicroPrint () linebreak = enqueueTile >> next where next = MicroPrint $ \w (opt,rgb,h) -> ((),w `snocH` LineBreak, (opt,rgb,h+1)) --- Note - it is permissible to change colour mid-word.--- But this is the same as having a no-space break.++-- | Change the current drawing colour. --+-- Note - it is permissible to change colour mid-word, but this +-- is the same as having a no-space break.+-- setRGB :: DRGB -> MicroPrint () setRGB rgb = enqueueTile >> next where -- tip will always be Start here... next = MicroPrint $ \w (tip,_,h) -> ((),w,(tip,rgb,h)) ++-- | Draw a character - note in the microprint, characters will +-- be concatenated together to make a word.+-- char :: MicroPrint () char = MicroPrint $ \w (tip,rgb,h) -> let (f,tip') = addChar tip in ((),f w,(tip',rgb,h))@@ -106,7 +120,8 @@ addChar (W0 n) = (id, W0 $ n+1) addChar (S0 n) = (\f -> f `snocH` (Space n), W0 1) -+-- | Draw a space.+-- space :: MicroPrint () space = MicroPrint $ \w (tip,rgb,h) -> let (f,tip') = addSpace tip rgb in ((),f w,(tip',rgb,h))
src/Wumpus/MicroPrint/Render.hs view
@@ -19,8 +19,8 @@ module Wumpus.MicroPrint.Render ( - DrawF - , MP_config(..)+ DrawWordF + , MicroPrintConfig(..) , greekF , borderedF @@ -31,7 +31,7 @@ import Wumpus.Core import Wumpus.Core.Colour ( black ) import Wumpus.Basic.Graphic-import Wumpus.Basic.Monads.ConsDrawing+import Wumpus.Basic.Monads.TurtleMonad import Wumpus.Basic.Utils.HList import Wumpus.MicroPrint.DrawMonad ( Tile(..), Height ) @@ -42,23 +42,33 @@ import Control.Applicative import Control.Monad --- | 'DrawF' :+-- | 'DrawWordF' : -- @ (num_chars, char_unit_width) * (full_width, full_height) -> rgb -> DGraphicF @ ---type DrawF = (Int,Double) -> (Double,Double) -> DRGB -> DGraphicF+-- The libraries currently provides two styles - 'greekF' and+-- 'borderedF'.+--+type DrawWordF = (Int,Double) -> (Double,Double) -> DRGB -> DGraphicF -data MP_config = MP_config +-- | Style properties for micro-print drawing.+--+data MicroPrintConfig = MicroPrintConfig { char_height :: Double , char_width :: Double , line_spacing :: Double - , drawF :: DrawF+ , drawWordF :: DrawWordF } -greekF :: DrawF+-- | Draw the word as a single coloured rectangle.+--+greekF :: DrawWordF greekF _ (w,h) rgb = wrapG . fill rgb . rectanglePath w h -borderedF :: Double -> DrawF++-- | Draw the word as a coloured rectangle, with a border grid.+--+borderedF :: Double -> DrawWordF borderedF ln_width (i,uw) (w,h) rgb = srect `cc` seps `cc` greekF (i,uw) (w,h) rgb where@@ -78,7 +88,9 @@ vline t h = \pt -> ostroke t $ path pt [lineTo $ pt .+^ vvec h] -newtype RenderMonad a = RM { getRM :: ReaderT MP_config (ConsDrawing Double) a }+newtype RenderMonad a = RM { + getRM :: ReaderT MicroPrintConfig + ( TurtleDrawing Double ) a } instance Functor RenderMonad where fmap f = RM . fmap f . getRM@@ -91,11 +103,10 @@ pure = return (<*>) = ap -instance TraceM RenderMonad DPrimitive where+instance TraceM RenderMonad Double where trace h = RM $ lift $ trace h- trace1 i = RM $ lift $ trace1 i -instance ReaderM RenderMonad MP_config where+instance ReaderM RenderMonad MicroPrintConfig where ask = RM $ ask instance TurtleM RenderMonad where@@ -105,16 +116,16 @@ setOrigin o = RM $ lift $ setOrigin o -drawMicroPrint :: MP_config -> ([Tile],Height) -> Maybe DPicture+drawMicroPrint :: MicroPrintConfig -> ([Tile],Height) -> Maybe DPicture drawMicroPrint cfg (xs,h) = let (_,hf) = runRender cfg (moveUpN h >> interpret xs) in post $ hf [] where post [] = Nothing post ps = Just $ frameMulti $ ps -runRender :: MP_config -> RenderMonad a -> (a, DGraphic)+runRender :: MicroPrintConfig -> RenderMonad a -> (a, DGraphic) runRender cfg m = - runConsDrawing (regularConfig 1) (0,0) (standardAttr 14) + runTurtleDrawing (regularConfig 1) (0,0) (standardAttr 14) $ runReaderT cfg $ getRM $ m interpret :: [Tile] -> RenderMonad ()@@ -128,7 +139,7 @@ h <- asks char_height uw <- asks char_width pt <- scaleCurrentCoord- dF <- asks drawF+ dF <- asks drawWordF trace (dF (i,uw) (w,h) rgb pt) moveRightN i
src/Wumpus/MicroPrint/VersionNumber.hs view
@@ -22,7 +22,7 @@ -- | Version number ----- > (0,3,0)+-- > (0,4,0) -- wumpus_microprint_version :: (Int,Int,Int)-wumpus_microprint_version = (0,3,0)+wumpus_microprint_version = (0,4,0)
wumpus-microprint.cabal view
@@ -1,5 +1,5 @@ name: wumpus-microprint-version: 0.3.0+version: 0.4.0 license: BSD3 license-file: LICENSE copyright: Stephen Tetley <stephen.tetley@gmail.com>@@ -17,9 +17,19 @@ for tokenizing input files, and at the moment it is really just a test bed for Wumpus. .+ Currently pictures are made within a monad providing /teletype/ + style operations. Other methods of drawing are possible, but + are yet to be implemented.+ . \[1\] <http://scg.unibe.ch/archive/papers/Robb05b-microprintsESUG.pdf> . Changelog:+ .+ 0.3.0 to 0.4.0:+ .+ * Implementation modules are now hidden. Added some documentation.+ .+ * DrawF renamed DrawWordF, MP_config renamed MicroPrintConfig. . 0.2.0 to 0.3.0: .@@ -47,16 +57,16 @@ vector-space >= 0.6, monadLib >= 3.6, wumpus-core >= 0.22.0,- wumpus-basic >= 0.3.0+ wumpus-basic >= 0.4.0 exposed-modules: Wumpus.MicroPrint,- Wumpus.MicroPrint.DrawMonad,- Wumpus.MicroPrint.Render, Wumpus.MicroPrint.VersionNumber other-modules:+ Wumpus.MicroPrint.DrawMonad,+ Wumpus.MicroPrint.Render extensions: