Graphics.Canvas
- Package
- purescript-canvas
- Repository
- paf31/purescript-canvas
This module defines foreign types and functions for working with the 2D Canvas API.
#CanvasElement Source
data CanvasElement :: Type
A canvas HTML element.
#CanvasImageSource Source
data CanvasImageSource :: Type
Opaque object for drawing elements and things to the canvas.
#CanvasPattern Source
data CanvasPattern :: Type
Opaque object describing a pattern.
#CanvasGradient Source
data CanvasGradient :: Type
Opaque object describing a gradient.
#tryLoadImage Source
tryLoadImage :: forall eff. String -> (Maybe CanvasImageSource -> Eff (canvas :: CANVAS | eff) Unit) -> Eff (canvas :: CANVAS | eff) Unit
Asynchronously load an image file by specifying its path.
#getCanvasElementById Source
getCanvasElementById :: forall eff. String -> Eff (canvas :: CANVAS | eff) (Maybe CanvasElement)
Get a canvas element by ID, or Nothing
if the element does not exist.
#getContext2D Source
getContext2D :: forall eff. CanvasElement -> Eff (canvas :: CANVAS | eff) Context2D
Get the 2D graphics context for a canvas element.
#getCanvasWidth Source
getCanvasWidth :: forall eff. CanvasElement -> Eff (canvas :: CANVAS | eff) Number
Get the canvas width in pixels.
#getCanvasHeight Source
getCanvasHeight :: forall eff. CanvasElement -> Eff (canvas :: CANVAS | eff) Number
Get the canvas height in pixels.
#setCanvasWidth Source
setCanvasWidth :: forall eff. Number -> CanvasElement -> Eff (canvas :: CANVAS | eff) CanvasElement
Set the canvas width in pixels.
#setCanvasHeight Source
setCanvasHeight :: forall eff. Number -> CanvasElement -> Eff (canvas :: CANVAS | eff) CanvasElement
Set the canvas height in pixels.
#Dimensions Source
type Dimensions = { height :: Number, width :: Number }
Canvas dimensions (width and height) in pixels.
#getCanvasDimensions Source
getCanvasDimensions :: forall eff. CanvasElement -> Eff (canvas :: CANVAS | eff) Dimensions
Get the canvas dimensions in pixels.
#setCanvasDimensions Source
setCanvasDimensions :: forall eff. Dimensions -> CanvasElement -> Eff (canvas :: CANVAS | eff) CanvasElement
Set the canvas dimensions in pixels.
#canvasToDataURL Source
canvasToDataURL :: forall eff. CanvasElement -> Eff (canvas :: CANVAS | eff) String
Create a data URL for the current canvas contents
#Composite Source
data Composite
Enumerates the different types of composite operations and blend modes.
Constructors
SourceOver
SourceIn
SourceOut
SourceAtop
DestinationOver
DestinationIn
DestinationOut
DestinationAtop
Lighter
Copy
Xor
Multiply
Screen
Overlay
Darken
Lighten
ColorDodge
ColorBurn
HardLight
SoftLight
Difference
Exclusion
Hue
Saturation
Color
Luminosity
Instances
#ScaleTransform Source
type ScaleTransform = { scaleX :: Number, scaleY :: Number }
An object representing a scaling transform:
- The scale factors in the
x
andy
directions,scaleX
andscaleY
.
#TranslateTransform Source
type TranslateTransform = { translateX :: Number, translateY :: Number }
An object representing a translation:
- The translation amounts in the
x
andy
directions,translateX
andtranslateY
.
#measureText Source
measureText :: forall eff. Context2D -> String -> Eff (canvas :: CANVAS | eff) TextMetrics
Measure some text.
#imageDataWidth Source
imageDataWidth :: ImageData -> Int
Get the width of an ImageData
object.
#imageDataHeight Source
imageDataHeight :: ImageData -> Int
Get the height of an ImageData
object.
#imageDataBuffer Source
imageDataBuffer :: ImageData -> Uint8ClampedArray
Get the underlying buffer from an ImageData
object.
#drawImageScale Source
drawImageScale :: forall eff. Context2D -> CanvasImageSource -> Number -> Number -> Number -> Number -> Eff (canvas :: CANVAS | eff) Context2D
#PatternRepeat Source
#createPattern Source
createPattern :: forall eff. CanvasImageSource -> PatternRepeat -> Context2D -> Eff (canvas :: CANVAS | eff) CanvasPattern
Create a new canvas pattern (repeatable image).
#setPatternFillStyle Source
setPatternFillStyle :: forall eff. CanvasPattern -> Context2D -> Eff (canvas :: CANVAS | eff) Context2D
Set the Context2D fillstyle to the CanvasPattern.
#LinearGradient Source
type LinearGradient = { x0 :: Number, x1 :: Number, y0 :: Number, y1 :: Number }
A type representing a linear gradient.
- Starting point coordinates: (
x0
,y0
) - Ending point coordinates: (
x1
,y1
)
#createLinearGradient Source
createLinearGradient :: forall eff. LinearGradient -> Context2D -> Eff (canvas :: CANVAS | eff) CanvasGradient
Create a linear CanvasGradient.
#createRadialGradient Source
createRadialGradient :: forall eff. RadialGradient -> Context2D -> Eff (canvas :: CANVAS | eff) CanvasGradient
Create a radial CanvasGradient.
#addColorStop Source
addColorStop :: forall eff. Number -> String -> CanvasGradient -> Eff (canvas :: CANVAS | eff) CanvasGradient
Add a single color stop to a CanvasGradient.
#setGradientFillStyle Source
setGradientFillStyle :: forall eff. CanvasGradient -> Context2D -> Eff (canvas :: CANVAS | eff) Context2D
Set the Context2D fillstyle to the CanvasGradient.
#QuadraticCurve Source
type QuadraticCurve = { cpx :: Number, cpy :: Number, x :: Number, y :: Number }
A type representing a quadratic Bézier curve.
- Bézier control point: (
cpx
,cpy
) - Ending point coordinates: (
x
,y
)
#quadraticCurveTo Source
quadraticCurveTo :: forall eff. QuadraticCurve -> Context2D -> Eff (canvas :: CANVAS | eff) Context2D
Draw a quadratic Bézier curve.
#bezierCurveTo Source
bezierCurveTo :: forall eff. BezierCurve -> Context2D -> Eff (canvas :: CANVAS | eff) Context2D
Draw a cubic Bézier curve.
- Modules
- Graphics.
Canvas