new canvas
Create a new canvas object.
canvas(w, h, divname)
canvas(w, h, divname)
Parameters:
| Name | Type | Argument | Description |
|---|---|---|---|
w |
Number in pixel | The Width of the canvas you want to create. | |
h |
Number in pixel | The Height of the canvas you want to create. | |
divname |
String |
<optional> |
The div id you want the create the canvas to. If not specified, the canvas will be hidden. |
- Source:
- codef_core.js, line 39
Properties:
| Name | Type | Description |
|---|---|---|
width |
Number in pixel | The Width of the canvas. |
height |
Number in pixel | The Height of the canvas. |
canvas |
Object | object of this canvas. ;) |
contex |
Object | the 2d context of this canvas. |
handlex |
Number in pixel | the x coord of the handle (0 by default). |
handley |
Number in pixel | the y coord of the handle (0 by default). |
tilew |
Number in pixel | the Width of a tile (IF this canvas is a tileset). |
tileh |
Number in pixel | the Height of a tile (IF this canvas is a tileset). |
tilestart |
Number | the number of the first tile (usefull for tileset like font). |
Example
var mycanvas = new canvas(640, 480, "main");
Methods
-
<static> clear
-
Clear the canvas.
- Source:
- codef_core.js, line 97
Example
mycanvas.clear(); -
<static> draw
-
Draw the canvas to another canvas.
canvas.draw(dst,x,y,alpha, rot,w,h)
Parameters:
Name Type Argument Description dstObject The destination canvas. xNumber in pixel The x coord in the destination canvas (based on the handle coord). yNumber in pixel The y coord in the destination canvas (based on the handle coord). alphaNumber <optional>
The normalized value of the alpha (1 by default). rotNumber <optional>
The rotation angle in degrees (0 by default) (will use the handle coord as rotation axis). wNumber <optional>
The normalized zoom factor on x (1 by default). hNumber <optional>
The normalized zoom factor on y (1 by default). - Source:
- codef_core.js, line 242
Example
mycanvas.draw(destcanvas,10,10,1,0,1,1); -
<static> drawPart
-
Draw a part of this canvas to another canvas.
canvas.drawPart(dst,x,y,partx,party,partw,parth,alpha, rot,zx,zy)
Parameters:
Name Type Argument Description dstObject The destination canvas. xNumber in pixel The x coord in the destination canvas (based on the handle coord). yNumber in pixel The y coord in the destination canvas (based on the handle coord). partxNumber in pixel The x coord of the part in the source canvas. partyNumber in pixel The y coord of the part in the source canvas. partwNumber in pixel The width of the part in the source canvas. parthNumber in pixel The height of the part in the source canvas. alphaNumber <optional>
The normalized value of the alpha (1 by default). rotNumber <optional>
The rotation angle in degrees (0 by default) (will use the handle coord as rotation axis). zxNumber <optional>
The normalized zoom factor on x (1 by default). zyNumber <optional>
The normalized zoom factor on y (1 by default). - Source:
- codef_core.js, line 306
Example
mycanvas.drawTile(mycanvas,10,10,0,0,50,50,1,0,1,1); -
<static> drawTile
-
Draw a tile from this canvas to another canvas.
canvas.drawTile(dst, nb, x, y, alpha, rot, w, h)
Parameters:
Name Type Argument Description dstObject The destination canvas. nbNumber the tile number. xNumber in pixel The x coord in the destination canvas (based on the handle coord). yNumber in pixel The y coord in the destination canvas (based on the handle coord). alphaNumber <optional>
The normalized value of the alpha (1 by default). rotNumber <optional>
The rotation angle in degrees (0 by default) (will use the handle coord as rotation axis). wNumber <optional>
The normalized zoom factor on x (1 by default). hNumber <optional>
The normalized zoom factor on y (1 by default). - Source:
- codef_core.js, line 281
Example
mycanvas.drawTile(destcanvas,5,10,10,1,0,1,1); -
<static> fill
-
Fill the canvas.
canvas.fill(color)
Parameters:
Name Type Description colorColor The color you want to fill the canvas with. - Source:
- codef_core.js, line 78
Example
mycanvas.fill('#FF0000'); -
<static> initTile
-
Init a tileset canvas.
canvas.initTile(tilew,tileh, tilestart)
Parameters:
Name Type Argument Description tilewNumber in pixel The Width of one tile. tilehNumber in pixel The Height of one tile. tilestartNumber <optional>
The number of the first tile. (0 by default) - Source:
- codef_core.js, line 224
Example
mycanvas.initTile(32,32); -
<static> line
-
Draw a line on the canvas.
canvas.line(x1,y1,x2,y2,width,color)
Parameters:
Name Type Description x1Number in pixel The x coord of the line start in the canvas. y1Number in pixel The y coord of the line start in the canvas. x2Number in pixel The x coord of the line end in the canvas. y2Number in pixel The y coord of the line end in the canvas. widthNumber in pixel The width of the line. colorColor The color of the plot. - Source:
- codef_core.js, line 124
Example
mycanvas.line(0,0,50,50,2,'#FF0000'); -
<static> plot
-
Draw a plot on the canvas.
canvas.plot(x1,y1,width,color)
Parameters:
Name Type Description xNumber in pixel The x coord you want to plot in the canvas. yNumber in pixel The y coord you want to plot in the canvas. widthNumber in pixel The size of the plot. colorColor The color of the plot. - Source:
- codef_core.js, line 108
Example
mycanvas.plot(20,20,50,'#FF0000'); -
<static> quad
-
Draw a filled quad on the canvas.
it can be used with 5 params :
canvas.quad(x1,y1,w,h,color)
or it can be used with 9 params :
canvas.quad(x1,y1,x2,y2,x3,y3,x4,y4,color)
Parameters:
Name Type Description x1Number in pixel The x coord of the 1st edge of the quad in the canvas. y1Number in pixel The y coord of the 1st edge of the quad in the canvas. x2Number in pixel The x coord of the 2nd edge of the quad in the canvas. y2Number in pixel The y coord of the 2nd edge of the quad in the canvas. x3Number in pixel The x coord of the 3rd edge of the quad in the canvas. y3Number in pixel The y coord of the 3rd edge of the quad in the canvas. x4Number in pixel The x coord of the 4th edge of the quad in the canvas. y4Number in pixel The y coord of the 4th edge of the quad in the canvas. wNumber in pixel The Width of the quad in the canvas. hNumber in pixel The Height of the quad in the canvas. colorColor The color of the plot. - Source:
- codef_core.js, line 175
Example
mycanvas.quad(150,150,250,250,'#FF0000'); or mycanvas.quad(0,150,300,150,250,250,50,250,'#FF0000'); -
<static> sethandle
-
Set the handle of the canvas.
canvas.sethandle(x,y)
Parameters:
Name Type Description xNumber in pixel The x coord of the handle of the canvas. yNumber in pixel The y coord of the handle of the canvas. - Source:
- codef_core.js, line 366
Example
mycanvas.sethandle(50,50); -
<static> setmidhandle
-
Set the handle coord of this canvas to the center.
- Source:
- codef_core.js, line 353
Example
mycanvas.setmidhandle(); -
<static> triangle
-
Draw a filled triangle on the canvas.
canvas.triangle(x1,y1,x2,y2,x3,y3,color)
Parameters:
Name Type Description x1Number in pixel The x coord of the 1st edge of the triangle in the canvas. y1Number in pixel The y coord of the 1st edge of the triangle in the canvas. x2Number in pixel The x coord of the 2nd edge of the triangle in the canvas. y2Number in pixel The y coord of the 2nd edge of the triangle in the canvas. x3Number in pixel The x coord of the 3rd edge of the triangle in the canvas. y3Number in pixel The y coord of the 3rd edge of the triangle in the canvas. colorColor The color of the plot. - Source:
- codef_core.js, line 150
Example
mycanvas.triangle(150,150,250,250,50,250,'#FF0000');