-
Notifications
You must be signed in to change notification settings - Fork 0
/
Canvas.js
50 lines (46 loc) · 1.4 KB
/
Canvas.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
class Canvas{
constructor(){
}
init = function(w = 500, h = 500){
this.w = w;
this.h = h;
this.createCanvas();
}
clr = function(){
this.ctx.clearRect(0,0,this.w, this.h);
}
fps = function(frames){
this.ctx.fillStyle = 'green';
this.ctx.font = "20px Comic Sans MS";
this.ctx.fillText(`fps: ${Math.floor(frames)}`, 10, 20);
this.ctx.fillStyle = 'white';
}
rect = function(x, y, width, height, color = 'black', fill = false){
this.ctx.fillStyle = color;
this.ctx.fillRect(x, y, width, height);
this.ctx.fillStyle = 'white';
}
arc = function(x, y, r, color="red", fill=false, border_color = 'black', family = 0){
this.ctx.fillStyle = color;
this.ctx.beginPath();
this.ctx.arc(x,y,r,0, 2* Math.PI);
if(fill){
this.ctx.fill();
}else{
}
this.ctx.strokeStyle = border_color;
this.ctx.stroke();
this.ctx.closePath();
this.ctx.fillStyle = 'white';
}
createCanvas = function(){
this.canvas = document.createElement('canvas');
this.canvas.width = this.w;
this.canvas.height = this.h;
document.getElementById('container').appendChild(this.canvas);
this.ctx = this.canvas.getContext('2d');
}
getContext = function(){
return this.ctx;
}
}