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 dst
Object The destination canvas. x
Number in pixel The x coord in the destination canvas (based on the handle coord). y
Number in pixel The y coord in the destination canvas (based on the handle coord). alpha
Number <optional>
The normalized value of the alpha (1 by default). rot
Number <optional>
The rotation angle in degrees (0 by default) (will use the handle coord as rotation axis). w
Number <optional>
The normalized zoom factor on x (1 by default). h
Number <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 dst
Object The destination canvas. x
Number in pixel The x coord in the destination canvas (based on the handle coord). y
Number in pixel The y coord in the destination canvas (based on the handle coord). partx
Number in pixel The x coord of the part in the source canvas. party
Number in pixel The y coord of the part in the source canvas. partw
Number in pixel The width of the part in the source canvas. parth
Number in pixel The height of the part in the source canvas. alpha
Number <optional>
The normalized value of the alpha (1 by default). rot
Number <optional>
The rotation angle in degrees (0 by default) (will use the handle coord as rotation axis). zx
Number <optional>
The normalized zoom factor on x (1 by default). zy
Number <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 dst
Object The destination canvas. nb
Number the tile number. x
Number in pixel The x coord in the destination canvas (based on the handle coord). y
Number in pixel The y coord in the destination canvas (based on the handle coord). alpha
Number <optional>
The normalized value of the alpha (1 by default). rot
Number <optional>
The rotation angle in degrees (0 by default) (will use the handle coord as rotation axis). w
Number <optional>
The normalized zoom factor on x (1 by default). h
Number <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 color
Color 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 tilew
Number in pixel The Width of one tile. tileh
Number in pixel The Height of one tile. tilestart
Number <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 x1
Number in pixel The x coord of the line start in the canvas. y1
Number in pixel The y coord of the line start in the canvas. x2
Number in pixel The x coord of the line end in the canvas. y2
Number in pixel The y coord of the line end in the canvas. width
Number in pixel The width of the line. color
Color 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 x
Number in pixel The x coord you want to plot in the canvas. y
Number in pixel The y coord you want to plot in the canvas. width
Number in pixel The size of the plot. color
Color 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 x1
Number in pixel The x coord of the 1st edge of the quad in the canvas. y1
Number in pixel The y coord of the 1st edge of the quad in the canvas. x2
Number in pixel The x coord of the 2nd edge of the quad in the canvas. y2
Number in pixel The y coord of the 2nd edge of the quad in the canvas. x3
Number in pixel The x coord of the 3rd edge of the quad in the canvas. y3
Number in pixel The y coord of the 3rd edge of the quad in the canvas. x4
Number in pixel The x coord of the 4th edge of the quad in the canvas. y4
Number in pixel The y coord of the 4th edge of the quad in the canvas. w
Number in pixel The Width of the quad in the canvas. h
Number in pixel The Height of the quad in the canvas. color
Color 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 x
Number in pixel The x coord of the handle of the canvas. y
Number 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 x1
Number in pixel The x coord of the 1st edge of the triangle in the canvas. y1
Number in pixel The y coord of the 1st edge of the triangle in the canvas. x2
Number in pixel The x coord of the 2nd edge of the triangle in the canvas. y2
Number in pixel The y coord of the 2nd edge of the triangle in the canvas. x3
Number in pixel The x coord of the 3rd edge of the triangle in the canvas. y3
Number in pixel The y coord of the 3rd edge of the triangle in the canvas. color
Color The color of the plot. - Source:
- codef_core.js, line 150
Example
mycanvas.triangle(150,150,250,250,50,250,'#FF0000');