These are all the methods of the ctx api, that you get from canvas.getContext('2d'). You can look at them all here. TheseCtxproperties and methods can be grouped together withbatchand then applied to aCanvasusingCtx.draw. For example, you could draw a line like this..
drawLine : Point -> Point -> Canvas -> Canvas
drawLine p0 p1 canvas =
[ Ctx.beginPath
, Ctx.lineWidth 2
, Ctx.moveTo p0
, Ctx.lineTo p1
, Ctx.stroke
]
|> Ctx.draw canvas
..or invert the color of a canvas like this
invert : Canvas -> Canvas
invert canvas =
[ Ctx.globalCompositionOp "difference"
, Ctx.fillStyle Color.white
, Ctx.fillRect
{ x = 0, y = 0 }
(Canvas.getSize canvas)
]
|> Ctx.draw canvas
You dont want to apply Ctx one at a time, its inefficient. Bundle many Ctx together in one batch, using batch.
line : Point -> Point -> Ctx
line p0 p1 =
[ Ctx.beginPath
, Ctx.lineWidth 2
, Ctx.moveTo p0
, Ctx.lineTo p1
, Ctx.stroke
]
|> Ctx.batch
Short for batch []. This is useful when you need to keep a Ctx somewhere, like in your model, but want to include the possibility of doing nothing.
Ctx represent all the methods of the ctx api. If you are familiar with JavaScript, its what comes from canvas.getContext('2d'). You can look at them all here.
Set the font before you draw text with fillText or strokeText
Ctx.font "48px sans-serif"
This is our primary way of drawing onto canvases. Give draw a drawOp and apply it to a canvas.
drawLine : Point -> Point -> Canvas -> Canvas
drawLine p0 p1 canvas =
[ Ctx.beginPath
, Ctx.lineWidth 2
, Ctx.moveTo p0
, Ctx.lineTo p1
, Ctx.stroke
]
|> Ctx.draw canvas
For the drawImage method, we made three different functions. This is becaus there are three different sets of parameters you can give the native javascript ctx.drawImage(). See here for more info
Draw a canvas at a point with a certain size
Take a canvas and crop a square out of it at a point and to a size, and draw the cropping at a point scaled to a certain size
Specifies the axis/axes along which to replicate a pattern. For use with the Pattern Style.
This is our primary way of drawing onto canvases. Give
drawadrawOpand apply it to a canvas.drawLine : Point -> Point -> Canvas -> Canvas drawLine p0 p1 canvas = [ Ctx.beginPath , Ctx.lineWidth 2 , Ctx.moveTo p0 , Ctx.lineTo p1 , Ctx.stroke ] |> Ctx.draw canvas