-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
32 lines (25 loc) · 955 Bytes
/
main.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
'use strict'
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
var rect=canvas.getBoundingClientRect();
var CButtons=[];
CButtons[0] = new CanvasButton(canvas,30,70,100,40,'test','white',true);
CButtons[1] = new CanvasButton(canvas,120,150,100,40,'test','white',true);
CButtons[2] = new CanvasButton(canvas,400,300,100,40,'test','white',true);
for (let i=0; i<CButtons.length; i++){
let ButtonName = 'B'+ (i+1);
document.getElementById(ButtonName).addEventListener('click',(evt)=> {
let buttonNr = parseInt(evt.target.id.slice(1,evt.target.length))-1;
CButtons[buttonNr].clickable ? CButtons[buttonNr].makeUnclickable() : CButtons[buttonNr].makeClickable();
})
}
function loop(){
ctx.clearRect(0,0,canvas.width,canvas.height);
ctx.fillStyle='lightgrey';
ctx.fillRect(0,0,canvas.width,canvas.height);
for (let CButton of CButtons){
CButton.draw();
}
requestAnimationFrame(loop);
}
loop();