Portability | GHC |
---|---|
Stability | highly unstable |
Maintainer | stephen.tetley@gmail.com |
Base types for Drawing Objects, Graphics / Images (a Graphic that also returns an answer), etc.
Base classes for monadic drawing.
Notes on prefix and suffix names:
Function types suffixed F
are functions from same-to-same, e.g.:
type Point2F u = Point2 u -> Point2 u
Functional types subfixed R
are functions from some static
context to the answer type (c.f the ReaderMonad), e.g.:
newtype DrawingR a = DrawingR { getDrawingR :: DrawingContext -> a }
The suffix M
is used for classes defining monadic actions.
The prefix Loc
indicates a functional type
from Point2 to something...
The prefix ThetaLoc
indicates a functional type
from Direction (radian) then Point to something...
** WARNING ** - some names are expected to change.
- class OPlus t where
- oplus :: t -> t -> t
- oconcat :: OPlus t => t -> [t] -> t
- anterior :: OPlus t => t -> t -> t
- superior :: OPlus t => t -> t -> t
- type family MonUnit m :: *
- class Monad m => TraceM m where
- class (Applicative m, Monad m) => DrawingCtxM m where
- askDC :: m DrawingContext
- localize :: (DrawingContext -> DrawingContext) -> m a -> m a
- asksDC :: DrawingCtxM m => (DrawingContext -> a) -> m a
- class Monad m => PointSupplyM m where
- data HPrim u
- hprimToList :: HPrim u -> [Primitive u]
- singleH :: Primitive u -> HPrim u
- type Point2F u = Point2 u -> Point2 u
- type DPoint2F = Point2F Double
- data DrawingR a
- type LocDrawingR u a = Point2 u -> DrawingR a
- type DLocDrawingR a = LocDrawingR Double a
- type DrawingTrafoF a = DrawingR a -> DrawingR a
- runDrawingR :: DrawingContext -> DrawingR a -> a
- data PrimGraphic u
- getPrimGraphic :: PrimGraphic u -> Primitive u
- wrapPrim :: Primitive u -> PrimGraphic u
- collectH :: PrimGraphic u -> HPrim u
- type Graphic u = DrawingR (PrimGraphic u)
- type DGraphic = Graphic Double
- type GraphicTrafoF u = Graphic u -> Graphic u
- superiorGraphic :: Graphic u -> GraphicTrafoF u
- anteriorGraphic :: Graphic u -> GraphicTrafoF u
- runGraphic :: DrawingContext -> Graphic u -> PrimGraphic u
- xlinkGraphic :: XLink -> Graphic u -> Graphic u
- type LocGraphic u = Point2 u -> Graphic u
- type DLocGraphic = LocGraphic Double
- type Image u a = DrawingR (a, PrimGraphic u)
- type DImage a = Image Double a
- type ImageTrafoF u a = Image u a -> Image u a
- intoImageTrafo :: DrawingTrafoF a -> GraphicTrafoF u -> ImageTrafoF u a
- imageTrafoDrawing :: DrawingTrafoF a -> ImageTrafoF u a
- imageTrafoGraphic :: GraphicTrafoF u -> ImageTrafoF u a
- type LocImage u a = Point2 u -> Image u a
- type DLocImage a = LocImage Double a
- runImage :: DrawingContext -> Image u a -> (a, PrimGraphic u)
- intoImage :: DrawingR a -> Graphic u -> Image u a
- intoLocImage :: LocDrawingR u a -> LocGraphic u -> LocImage u a
- xlinkImage :: XLink -> Image u a -> Image u a
- type ConnectorDrawingR u a = Point2 u -> Point2 u -> DrawingR a
- type DConnectorDrawingR a = ConnectorDrawingR Double a
- type ConnectorGraphic u = Point2 u -> Point2 u -> Graphic u
- type DConnectorGraphic = ConnectorGraphic Double
- type ConnectorImage u a = Point2 u -> Point2 u -> Image u a
- type DConnectorImage a = ConnectorImage Double a
- intoConnectorImage :: ConnectorDrawingR u a -> ConnectorGraphic u -> ConnectorImage u a
- type ThetaLocDrawingR u a = Radian -> LocDrawingR u a
- type DThetaLocDrawingR a = ThetaLocDrawingR Double a
- type ThetaLocGraphic u = Radian -> LocGraphic u
- type DThetaLocGraphic = ThetaLocGraphic Double
- type ThetaLocImage u a = Radian -> LocImage u a
- type DThetaLocImage a = ThetaLocImage Double a
- intoThetaLocImage :: ThetaLocDrawingR u a -> ThetaLocGraphic u -> ThetaLocImage u a
Documentation
A Semigroup class.
Drawing monads.
type family MonUnit m :: *Source
DUnit is always for fully saturated type constructors, so (seemingly) an equivalent type family is needed for monads.
class Monad m => TraceM m whereSource
Collect elementary graphics as part of a larger drawing.
TraceM works much like a writer monad.
class (Applicative m, Monad m) => DrawingCtxM m whereSource
askDC :: m DrawingContextSource
localize :: (DrawingContext -> DrawingContext) -> m a -> m aSource
DrawingCtxM DrawingR | |
DrawingCtxM (Drawing u) | |
Monad m => DrawingCtxM (DrawingT u m) | |
DrawingCtxM m => DrawingCtxM (TurtleT u m) | |
DrawingCtxM m => DrawingCtxM (ScalingT ux uy u m) |
asksDC :: DrawingCtxM m => (DrawingContext -> a) -> m aSource
Project a value out of a context.
class Monad m => PointSupplyM m whereSource
A monad that supplies points, e.g. a turtle monad.
(u ~ MonUnit m, Monad m, Num u) => PointSupplyM (TurtleT u m) |
Base types
Graphics objects, even simple ones (line, arrow, dot) might need more than one primitive (path or text label) for their construction. Hence, the primary representation that all the others are built upon must support concatenation of primitives.
Wumpus-Core has a type Picture - made from one or more Primitives - but Pictures include support for affine frames. For drawing many simple graphics (dots, connector lines...) that do not need individual affine transformations this is a penalty. A list of Primitives is therefore more suitable representation, and a Hughes list which supports efficient concatenation is wise.
hprimToList :: HPrim u -> [Primitive u]Source
Drawings in Wumpus-Basic have an implicit graphics state
the DrawingContext
, the most primitive building block is
a function from the DrawingContext to some polymorphic answer.
This functional type is represented concretely as DrawingR
.
DrawingR :: DrawingContext -> a
type LocDrawingR u a = Point2 u -> DrawingR aSource
type DLocDrawingR a = LocDrawingR Double aSource
type DrawingTrafoF a = DrawingR a -> DrawingR aSource
runDrawingR :: DrawingContext -> DrawingR a -> aSource
Run a Drawing Function with the supplied Drawing Context.
data PrimGraphic u Source
Eq u => Eq (PrimGraphic u) | |
Show u => Show (PrimGraphic u) | |
(Real u, Floating u) => Rotate (PrimGraphic u) | |
(Real u, Floating u) => RotateAbout (PrimGraphic u) | |
Num u => Scale (PrimGraphic u) | |
Num u => Translate (PrimGraphic u) | |
OPlus (PrimGraphic u) |
getPrimGraphic :: PrimGraphic u -> Primitive uSource
wrapPrim :: Primitive u -> PrimGraphic uSource
collectH :: PrimGraphic u -> HPrim uSource
type Graphic u = DrawingR (PrimGraphic u)Source
type GraphicTrafoF u = Graphic u -> Graphic uSource
superiorGraphic :: Graphic u -> GraphicTrafoF uSource
anteriorGraphic :: Graphic u -> GraphicTrafoF uSource
runGraphic :: DrawingContext -> Graphic u -> PrimGraphic uSource
xlinkGraphic :: XLink -> Graphic u -> Graphic uSource
type LocGraphic u = Point2 u -> Graphic uSource
Commonly graphics take a start point as well as a drawing context.
Here they are called a LocGraphic - graphic with a (starting) location.
type DLocGraphic = LocGraphic DoubleSource
type Image u a = DrawingR (a, PrimGraphic u)Source
Images return a value as well as drawing. A node is a typical example - nodes are drawing but the also support taking anchor points.
type ImageTrafoF u a = Image u a -> Image u aSource
intoImageTrafo :: DrawingTrafoF a -> GraphicTrafoF u -> ImageTrafoF u aSource
imageTrafoDrawing :: DrawingTrafoF a -> ImageTrafoF u aSource
imageTrafoGraphic :: GraphicTrafoF u -> ImageTrafoF u aSource
runImage :: DrawingContext -> Image u a -> (a, PrimGraphic u)Source
intoLocImage :: LocDrawingR u a -> LocGraphic u -> LocImage u aSource
xlinkImage :: XLink -> Image u a -> Image u aSource
type ConnectorDrawingR u a = Point2 u -> Point2 u -> DrawingR aSource
type DConnectorDrawingR a = ConnectorDrawingR Double aSource
type ConnectorGraphic u = Point2 u -> Point2 u -> Graphic uSource
ConnectorGraphic is a connector drawn between two points contructing a Graphic.
type ConnectorImage u a = Point2 u -> Point2 u -> Image u aSource
ConnectorImage is a connector drawn between two points constructing an Image.
Usually the answer type of a ConnectorImage will be a Path so
the Points ar midway
, atstart
etc. can be taken on it.
type DConnectorImage a = ConnectorImage Double aSource
intoConnectorImage :: ConnectorDrawingR u a -> ConnectorGraphic u -> ConnectorImage u aSource
type ThetaLocDrawingR u a = Radian -> LocDrawingR u aSource
type DThetaLocDrawingR a = ThetaLocDrawingR Double aSource
type ThetaLocGraphic u = Radian -> LocGraphic uSource
A function from Radian -\> Point -\> Graphic...
type ThetaLocImage u a = Radian -> LocImage u aSource
type DThetaLocImage a = ThetaLocImage Double aSource
intoThetaLocImage :: ThetaLocDrawingR u a -> ThetaLocGraphic u -> ThetaLocImage u aSource