new Canvas(options)
Class representing a canvas
Parameters:
Name | Type | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object | Options for the canvas creation
Properties
|
Classes
Members
canvas :HTMLCanvasElement
The canvas element object
Type:
- HTMLCanvasElement
context :CanvasRenderingContext2D
Context of the canvas
Type:
- CanvasRenderingContext2D
filters :FilterManager
Filters for the canvas
Type:
Methods
applyFilter(filter) → {void}
Applies a filter to the canvas
Parameters:
Name | Type | Description |
---|---|---|
filter |
Filter | Filter to be applied |
Returns:
- Type
- void
clear() → {void}
Clears the canvas
Returns:
- Type
- void
clearFilters() → {void}
Clears all filters
Returns:
- Type
- void
clearRect(x, y, width, height) → {void}
Clears a rectangle
Parameters:
Name | Type | Description |
---|---|---|
x |
Number | The x coordinate of the upper left corner of the rectangle |
y |
Number | The y coordinate of the upper left corner of the rectangle |
width |
Number | The width of the rectangle |
height |
Number | The height of the rectangle |
Returns:
- Type
- void
createPath() → {Path}
Creates a path
Returns:
- Type
- Path
drawGrid(width)
Draws a grid
Parameters:
Name | Type | Default | Description |
---|---|---|---|
width |
Number | 50 | How far apart should the lines of the grid be |
drawImage(image, x, y) → {void}
Draws an image to the canvas
Parameters:
Name | Type | Description |
---|---|---|
image |
Image | The image to be drawn |
x |
Number | The X coordinate of the upper left corner |
y |
Number | The Y coordinate of the upper left corner |
Returns:
- Type
- void
drawLine(A, B) → {void}
Parameters:
Name | Type | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
A |
Object | Point A
Properties
|
||||||||||||
B |
Object | Point B
Properties
|
Returns:
- Type
- void
fillRect(x, y, width, height) → {void}
Fills a rectangle
Parameters:
Name | Type | Description |
---|---|---|
x |
Number | The x coordinate of the upper left corner of the rectangle |
y |
Number | The y coordinate of the upper left corner of the rectangle |
width |
Number | The width of the rectangle |
height |
Number | The height of the rectangle |
Returns:
- Type
- void
getAllFilters() → {FilterManager}
Returns all the filters
Returns:
- Type
- FilterManager
getImageData(rectangle) → {ImageData}
Returns ImageData object with pixels from the rectangle from the canvas
Parameters:
Name | Type | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
rectangle |
Object | Object represnting the rectangle
Properties
|
Returns:
- Type
- ImageData
getLineDash() → {LineDashPattern}
Gets the line dashing pattern
Returns:
- Type
- LineDashPattern
getTransform() → {DOMMatrix2DInit}
Gets the transform matrix
Returns:
- Type
- DOMMatrix2DInit
load() → {void}
Loads the last saved canvas from the stack
Returns:
- Type
- void
rect(x, y, width, height) → {void}
Draws a rectangle outline
Parameters:
Name | Type | Description |
---|---|---|
x |
Number | The x coordinate of the upper left corner of the rectangle |
y |
Number | The y coordinate of the upper left corner of the rectangle |
width |
Number | The width of the rectangle |
height |
Number | The height of the rectangle |
Returns:
- Type
- void
removeFilter(filter)
Removes a filter
Parameters:
Name | Type | Description |
---|---|---|
filter |
Number | Filter |
rotate(angle) → {void}
Rotates the canvas
Parameters:
Name | Type | Description |
---|---|---|
angle |
Number | Angle of rotation in radians |
Returns:
- Type
- void
save() → {void}
Saves the currect state of the canvas to stack. Can be restored using Canvas.load()
Returns:
- Type
- void
scale(x, y) → {void}
Scales the canvas
Parameters:
Name | Type | Default | Description |
---|---|---|---|
x |
Number | 1 | X axis scale |
y |
Number | 1 | Y axis scale |
Returns:
- Type
- void
setDirection(direction) → {void}
Sets text direction
Parameters:
Name | Type | Default | Description |
---|---|---|---|
direction |
"ltr" | "rtl" | "inherit" | inherit | Direction of the text |
Returns:
- Type
- void
setFill(style) → {void}
Sets the fill style
Parameters:
Name | Type | Description |
---|---|---|
style |
String | CanvasGradient | CanvasPattern | Syle of fill (color | gradient | image) |
Returns:
- Type
- void
setFont(font) → {void}
Sets the font style
Parameters:
Name | Type | Description |
---|---|---|
font |
String | String represnting the css style font |
Returns:
- Type
- void
setGlobalAlpha(alpha) → {void}
Sets global alpha for all drawn objects
Parameters:
Name | Type | Description |
---|---|---|
alpha |
Number | Number between 0 and 1 representing the global alpha value |
Returns:
- Type
- void
setGlobalCompositeOperation(operation)
Sets the global composite operation. For more information about operations visit offical MDN documentation
Parameters:
Name | Type | Description |
---|---|---|
operation |
"source-over" | "source-in" | "source-out" | "source-atop" | "destination-over" | "destination-in" | "destination-out" | "destination-atop" | "lighter" | "copy" | "xor" | "multiply" | "screen" | "overlay" | "darken" | "lighten" | "color-dodge" | "color-burn" | "hard-light" | "soft-light" | "difference" | "exclusion" | "hue" | "saturation" | "color" | "luminosity" | The operation |
setImageSmooth(imageSmoothingMode) → {void}
Sets the image smoothing
Parameters:
Name | Type | Description |
---|---|---|
imageSmoothingMode |
"disabled" | "low" | "medium" | "high" |
Returns:
- Type
- void
setLineCap(cap) → {void}
Sets the type of line endings
Parameters:
Name | Type | Default | Description |
---|---|---|---|
cap |
"butt" | "round" | "square" | butt | Type of cap |
Returns:
- Type
- void
setLineDash(lineWidth) → {void}
Sets the spacing of a line
Parameters:
Name | Type | Description |
---|---|---|
lineWidth |
Array.<Number> |
Returns:
- Type
- void
setLineDashOffset(offset) → {void}
Sets the line dash offset
Parameters:
Name | Type | Description |
---|---|---|
offset |
Number | The offset of the line dash |
Returns:
- Type
- void
setLineJoin(join) → {void}
Sets the type of corners where two lines meet
Parameters:
Name | Type | Default | Description |
---|---|---|---|
join |
"round" | "bevel" | "miter" | miter | Type of line join |
Returns:
- Type
- void
setLineWidth(width) → {void}
Sets line width
Parameters:
Name | Type | Description |
---|---|---|
width |
Number |
Returns:
- Type
- void
setMiterLimit(limit) → {void}
Sets the miter limit
Parameters:
Name | Type | Description |
---|---|---|
limit |
Number |
Returns:
- Type
- void
setShadowBlur(level) → {void}
Sets the shadow blur. Default is 0, higher level is more blur
Parameters:
Name | Type | Description |
---|---|---|
level |
Number | Blur level |
Returns:
- Type
- void
setShadowColor(color) → {void}
Sets the shadow color
Parameters:
Name | Type | Description |
---|---|---|
color |
String | CSS style color |
Returns:
- Type
- void
setShadowOffset(xnullable, ynullable) → {void}
Sets shadow offset
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
x |
Number |
<nullable> |
X shadow offset |
y |
Number |
<nullable> |
Y shadow offset |
Returns:
- Type
- void
setStroke(style) → {void}
Sets the stroke style
Parameters:
Name | Type | Description |
---|---|---|
style |
String | CanvasGradient | CanvasPattern | Syle of stroke (color | gradient | image) |
Returns:
- Type
- void
setTextAlign(textAlign) → {void}
Sets the text align
Parameters:
Name | Type | Default | Description |
---|---|---|---|
textAlign |
"start" | "end" | "left" | "right" | "center" | start | Text align type |
Returns:
- Type
- void
setTextBaseline(textBaseline) → {void}
Sets the test baseline
Parameters:
Name | Type | Default | Description |
---|---|---|---|
textBaseline |
"top" | "hanging" | "middle" | "alphabetic" | "ideographic" | "bottom" | alphabetic | Text baseline style |
Returns:
- Type
- void
setTransform(transform) → {void}
Sets the transform matrix
Parameters:
Name | Type | Description |
---|---|---|
transform |
DOMMatrix2DInit |
Returns:
- Type
- void
text(text, x, y, maxWidthnullable) → {void}
Draws a text on the canvas
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
text |
String | Text to be drawn on canvas | |
x |
Number | The x coordinate of the upper left corner of the text | |
y |
Number | The y coordinate of the upper left corner of the text | |
maxWidth |
Number |
<nullable> |
Max width of the text |
Returns:
- Type
- void
textOutline(text, x, y, maxWidthnullable) → {void}
Draws a text outline on the canvas
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
text |
String | Text to be drawn on canvas | |
x |
Number | The x coordinate of the upper left corner of the text | |
y |
Number | The y coordinate of the upper left corner of the text | |
maxWidth |
Number |
<nullable> |
Max width of the text |
Returns:
- Type
- void
transform(optionsnullable) → {void}
Transforms the canvas according to the provided properties. If no options argument provided, this function will reset the transformation.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
<nullable> |
Properties
|
Returns:
- Type
- void
translate(x, y) → {void}
Moves the zero point of the canvas
Parameters:
Name | Type | Default | Description |
---|---|---|---|
x |
Number | 0 | X axis move |
y |
Number | 0 | Y axis move |
Returns:
- Type
- void