Canvas
This class handles and simplifies much of the drawing
init -> {Integer || Function}
creates the canvas tag, initializes the context and returns an ID that referenes the current canvas
| Name | Type | Description |
|---|---|---|
| $t | Object | a DOM object to append the canvas to
example: document.getElemetById("target") (optional) defaults to the <body> tag |
| w | Number |
The width of the canvas
(optional) defaults to browser window innerWidth |
| h | Number |
The height of the canvas
(optional) defaults to browser window innerHeight |
| callback | Function | (optional) a callback function that returns the canvas ID |
circle -> {Void}
creates a circle ( filled, stroke or both )
| Name | Type | Description |
|---|---|---|
| i | Integer | reference to the canvas |
| x | Number | x coordinate |
| y | Number | y coordinate |
| radius | Number | the radius of the circle |
| color | String | a hexadecimal color example: ( #000000 ) |
| opacity | Float | ( 0 - 1 ) |
| fint | Boolean | if true float-point numbers for coordinates will be converted to whole integer ( default is true ) |
arc -> {Void}
creates a basic arc
| Name | Type | Description |
|---|---|---|
| i | Integer | reference to the canvas |
| x | Number | x coordinate |
| y | Number | y coordinate |
| radius | Number | the radius of the circle |
| s | Number | start angle |
| e | Number | end angle |
| cc | Boolean | if true the arc is drawn counter-clockwize |
| color | String | a hexadecimal color example: ( #000000 ) |
| fint | Boolean | if true float-point numbers for coordinates will be converted to whole integer ( default is true ) |
qArc -> {Void}
creates a quadratic curve
| Name | Type | Description |
|---|---|---|
| i | Integer | reference to the canvas |
| x1 | Number | x1 coordinate |
| y1 | Number | y1 coordinate |
| x2 | Number | x2 coordinate |
| y2 | Number | y2 coordinate |
| x3 | Number | x3 coordinate |
| y3 | Number | y3 coordinate |
| color | String | a hexadecimal color example: ( #000000 ) |
| fint | Boolean | if true float-point numbers for coordinates will be converted to whole integer ( default is true ) |
bArc -> {Void}
creates a bezier curve
| Name | Type | Description |
|---|---|---|
| i | Integer | reference to the canvas |
| x1 | Number | x1 coordinate |
| y1 | Number | y1 coordinate |
| x2 | Number | x2 coordinate |
| y2 | Number | y2 coordinate |
| x3 | Number | x3 coordinate |
| y3 | Number | y3 coordinate |
| x4 | Number | x4 coordinate |
| y4 | Number | y4 coordinate |
| color | String | a hexadecimal color example: ( #000000 ) |
| fint | Boolean | if true float-point numbers for coordinates will be converted to whole integer ( default is true ) |
text -> {Void}
draws text to the canvas
| Name | Type | Description |
|---|---|---|
| i | Integer | reference to the canvas |
| x | Number | x coordinate |
| y | Number | y coordinate |
| txt | String | the text to display |
| m | Enum | stroke, fill |
| font | String |
[font-size] [font-family] [font-style]
24px Arial italic |
| color | String | a hexadecimal color example: ( #000000 ) |
| fint | Boolean | if true float-point numbers for coordinates will be converted to whole integer ( default is true ) |
line -> {Void}
draws a line to the canvas
| Name | Type | Description |
|---|---|---|
| i | Integer | reference to the canvas |
| x1 | Number | x1 coordinate |
| y1 | Number | y1 coordinate |
| x2 | Number | x2 coordinate |
| y2 | Number | y2 coordinate |
| color | String | a hexadecimal color example: ( #000000 ) |
| lineWidth | Number | |
| fint | Boolean | if true float-point numbers for coordinates will be converted to whole integer ( default is true ) |
rectangle -> {Void}
draws a rectangle to the canvas
| Name | Type | Description |
|---|---|---|
| i | Integer | reference to the canvas |
| x1 | Number | x1 coordinate |
| y1 | Number | y1 coordinate |
| x2 | Number | x2 coordinate note: this is relative to the x1 coordinate |
| y2 | Number | y2 coordinate note: this is relative to the y1 coordinate |
| color | String | a hexadecimal color example: ( #000000 ) |
| m | Enum | stroke, fill |
| acolor | String | a hexadecimal color example: ( #000000 ) |
| opacity | Float | ( 0 - 1 ) |
| fint | Boolean | if true float-point numbers for coordinates will be converted to whole integer ( default is true ) |
roundRectangle -> {Void}
draws a round rectangle to the canvas
| Name | Type | Description |
|---|---|---|
| i | Integer | reference to the canvas |
| x | Number | x coordinate |
| y | Number | y coordinate |
| width | Number | width of the rectangle |
| height | Number | height of rectangle |
| color | String | a hexadecimal color example: ( #000000 ) |
| m | Enum | stroke, fill |
| acolor | String | a hexadecimal color example: ( #000000 ) |
| opacity | Float | ( 0 - 1 ) |
| fint | Boolean | if true float-point numbers for coordinates will be converted to whole integer ( default is true ) |
polygon -> {Void}
draws a polygon to the canvas
| Name | Type | Description |
|---|---|---|
| i | Integer | reference to the canvas |
| a | Array |
a two dimensional array containing the coordinates of the polygon
[ [ x,y ],[ x,y ],[ x,y ] ] |
| color | String | a hexadecimal color example: ( #000000 ) |
| m | Enum | stroke, fill |
| acolor | String | a hexadecimal color example: ( #000000 ) |
| opacity | Float | ( 0 - 1 ) |
| fint | Boolean | if true float-point numbers for coordinates will be converted to whole integer ( default is true ) |
image -> {Void}
draws a bitmap image to the canvas
| Name | Type | Description | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| i | Integer | reference to the canvas | ||||||||||||||||||||||||||||||
| obj | Object |
|
||||||||||||||||||||||||||||||
| fint | Boolean | if true float-point numbers for coordinates will be converted to whole integer ( default is true ) |
clear -> {Void}
clears the referenced canvas
| Name | Type | Description |
|---|---|---|
| i | Integer | reference to the canvas |
| save | Boolean |
zIndex -> {Void}
Sets the z-index of the target canvas
| Name | Type | Description |
|---|---|---|
| i | Integer | reference to the canvas |
| z | Integer |
get -> {Object}
gets the referenced canvas or context
| Name | Type | Description |
|---|---|---|
| i | Integer | reference to the canvas |
| o | Enum | canvas, ctx |
pop -> {Void}
remove last context
set_error -> {Void}
appends an error message to an array
| Name | Type | Description |
|---|---|---|
| e | String | The error message |