@lucas08911/j2d 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/j2d.js +45 -0
- package/package.json +12 -0
package/j2d.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export class J2D {
|
|
2
|
+
constructor(canvas, width = window.innerWidth, height = window.innerHeight){
|
|
3
|
+
// if canvas no worki throw error ball
|
|
4
|
+
if (!canvas){
|
|
5
|
+
throw new Error("No canvas found.")
|
|
6
|
+
}
|
|
7
|
+
// if canvas not real canvas throw error ball
|
|
8
|
+
if (!(canvas instanceof HTMLCanvasElement)){
|
|
9
|
+
throw new Error("Invaild Canvas.")
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
this.c = canvas // set c to canvas
|
|
13
|
+
this.cc = this.c.getContext("2d") // get context
|
|
14
|
+
// if context failed throw error ball
|
|
15
|
+
if(!this.cc){
|
|
16
|
+
throw new Error("Failed to get 2D Context.")
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
this.c.width = width // set width and height
|
|
20
|
+
this.c.height = height
|
|
21
|
+
// 2d stuff done
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
drawRect(x, y, w, h, color = "black"){
|
|
25
|
+
this.cc.fillStyle = color // set color
|
|
26
|
+
this.cc.fillRect(x,y,w,h) // done rendering the rect
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
clear(){
|
|
30
|
+
this.cc.clearRect(0, 0, this.c.width, this.c.height) // done clearing the screen
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
drawCircle(x, y, r, color = "black"){
|
|
34
|
+
this.cc.beginPath() // start path
|
|
35
|
+
this.cc.arc(x, y, r, 0, Math.PI * 2) // set arc
|
|
36
|
+
this.cc.fillStyle = color // set color
|
|
37
|
+
this.cc.fill() // start filling
|
|
38
|
+
this.cc.closePath() // end path
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
setSize(w, h){
|
|
42
|
+
this.c.width = w
|
|
43
|
+
this.c.height = h
|
|
44
|
+
}
|
|
45
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lucas08911/j2d",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A 2d engine.",
|
|
5
|
+
"main": "j2d.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
},
|
|
8
|
+
"keywords": ["canvas", "2d", "engine", "graphics"],
|
|
9
|
+
"author": "lucas0891",
|
|
10
|
+
"license": "GPL-3.0-only",
|
|
11
|
+
"type": "module"
|
|
12
|
+
}
|