Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
Latest commit
55 lines (44 loc) · 1.46 KB
/
Copy pathmain.js
File metadata and controls
55 lines (44 loc) · 1.46 KB
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
51
52
53
54
55
import{Background}from'./Background.js'
constcanvas=document.getElementById('background-grid')
constctx=canvas.getContext('2d')
constbackground=newBackground(canvas,50,10)
background.style.grid.lineWidth=1
background.style.grid.color='#2d333b'
// resize page
window.addEventListener('resize',()=>{
background.resize(window.innerWidth,window.innerHeight)
})
background.resize(window.innerWidth,window.innerHeight)
// move background grid
canvas.addEventListener('mousemove',event=>{
// only move if left mouse button is pressed
if(event.buttons==1){
background.moveBy(event.movementX,event.movementY)
}
})
// zoom in and out
canvas.addEventListener('wheel',event=>{
// zoom in
if(event.deltaY<0){
background.zoomAt(event.clientX,event.clientY,true)
}
// zoom out
elseif(event.deltaY>0){
background.zoomAt(event.clientX,event.clientY,false)
}
})
// move origin to center of page
background.moveTo(canvas.width/2,canvas.height/2)
background.update(()=>{
ctx.fillStyle='#c93c37'
ctx.strokeStyle='#539bf5'
ctx.beginPath()
ctx.moveTo(window.innerWidth/2,window.innerHeight/2);
ctx.lineTo(background.getOrigin().posX,background.getOrigin().posY)
ctx.stroke()
ctx.closePath()
ctx.beginPath()
ctx.arc(background.getOrigin().posX,background.getOrigin().posY,5,0,2*Math.PI);
ctx.fill()
ctx.closePath()
})