Module

Reactor.Graphics.Drawing

Package
purescript-grid-reactors
Repository
Eugleo/purescript-grid-reactors

This module provides the means of producing a drawing of the reactor's world. The drawing is then rendered on canvas. Currently, only grid-based drawings are supported.

#Drawing Source

type Drawing = DrawingM Unit

DrawingM is usually too general; our drawing-contructing functions don't need to return anything. Internal implementation detail.

Usually, constructing a drawing will look something like this.

drawTwoPoints :: CoordinateSystem Point -> CoordinateSystem Point -> Drawing
drawTwoPoints blueXY redXY = do
  fill Color.blue400 $ tile blueXY
  fill Color.red400 $ tile redXY

#DrawingM Source

newtype DrawingM a

A free monad for DrawingF that enables you to use do-notation when constructing drawings. Just an internal implementation detail.

Constructors

Instances

#DrawingF Source

data DrawingF a

A DSL for constructing drawings. Currently, only filled shapes are supported. DrawingF is for internal use. You should construct a drawing by calling the different helper functions, like fill, instead of manually calling the DrawingF data contructors.

Constructors

Instances

#fill Source

fill :: Color -> Shape -> Drawing

Given a shape (e.g. a rectangle), draw it and fill it with the provided color.

#drawGrid Source

drawGrid :: forall a. Grid a -> (a -> Maybe Color) -> Drawing

This function produces a drawing from a grid. For each cell in the grid, it calls the supplied (a -> Maybe Color) function to obtain its color. The cell is then drawn it using the fill and tile functions.

#drawGridWithIndex Source

drawGridWithIndex :: forall a. Grid a -> (Coordinates -> a -> Maybe Color) -> Drawing

A function almost identical to drawGrid, only the function matching colors to grid cells is provided with an index of the cell in addition to the value of the cell.

#Shape Source

data Shape

Constructors

#tile Source

tile :: Coordinates -> Shape

A 1-square tile on the given point in the grid.