Module

Graphics.CanvasAction.Path

Package
purescript-canvas-action
Repository
3ddyy/purescript-canvas-action

This module defines a free monad for working with canvas paths in a more pleasant way. Make your paths by combining lineTo, moveTo, arc, rect, quadraticCurveTo, bezierCurveTo, and closePath using <> or bind (do notation), and use them with fillPath, fillPathWith, strokePath, strokePathWith, and clip.

Example:

action :: CanvasAction
action = fillPathWith "red" path

path :: Path
path = do
  moveTo (100.0 >< 100.0)
  lineTo (200.0 >< 10.0)
  lineTo (10.0 >< 100.0)
  closePath
  polygon
    [ 0.0 >< 0.0
    , 20.0 >< 200.0
    , 100.0 >< 175.0
    , 30.0 >< 150.0
    ]
  circle (100.0 >< 100.0) 50.0

action is a CanvasAction that can be run in Effect with runAction from Graphics.CanvasAction.

#PathF Source

data PathF a

Instances

#PathM Source

#Path Source

type Path = PathM Unit

#lineTo Source

lineTo :: forall p. ToPos Number p => p -> Path

#moveTo Source

moveTo :: forall p. ToPos Number p => p -> Path

#arc Source

arc :: Arc -> Path

#rect Source

rect :: forall r. ToRegion Number r => r -> Path

#closePath Source

#fillPath Source

fillPath :: forall m. MonadCanvasAction m => MonadRec m => PathM ~> m

#fillPathWith Source

fillPathWith :: forall m r. MonadCanvasAction m => MonadRec m => CanvasStyleRep r => r -> PathM ~> m

#strokePath Source

strokePath :: forall m. MonadCanvasAction m => MonadRec m => PathM ~> m

#strokePathWith Source

strokePathWith :: forall m r. MonadCanvasAction m => MonadRec m => CanvasStyleRep r => r -> PathM ~> m

#clip Source

clip :: forall m. MonadCanvasAction m => MonadRec m => PathM ~> m

#polygon Source

polygon :: forall p f. ToPos Number p => Foldable f => f p -> Path

Draw a polygon with the specified points. Starts and ends on the first point.

#circle Source

circle :: forall p. ToPos Number p => p -> Number -> Path

Draw a circle with the specified center and radius. Ends on the rightmost point of the circle.