-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
67 lines (59 loc) · 2.31 KB
/
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
document.addEventListener("pointerdown", (e) => {
const dot = document.createElement("div")
dot.id = e.pointerId
dot.classList.add("dot")
doDotShit(dot, e)
document.body.appendChild(dot)
console.log(e)
})
document.addEventListener("pointermove", (e) => {
const dot = document.getElementById(e.pointerId)
doDotShit(dot, e)
})
document.addEventListener("pointerup", (e) => {
const dot = document.getElementById(e.pointerId)
document.body.removeChild(dot)
})
function doDotShit(dot, e) {
if(dot) {
dot.style.top = e.pageY + "px"
dot.style.left = e.pageX + "px"
if(e.pointerType == "touch") {
dot.style.height = (e.height + 10) * e.pressure * 2 + "px"
dot.style.width = (e.width + 10) * e.pressure * 2 + "px"
}
if(e.pointerType == "pen") {
dot.style.height = (Math.abs(e.tiltY) + 10) * e.pressure * 2 + "px"
dot.style.width = (Math.abs(e.tiltX) + 10) * e.pressure * 2 + "px"
}
}
}
const screenHeight = document.body.clientHeight
const screenWidth = document.body.clientWidth
let score = 0
const randomInterval = setInterval(() => {
if(document.getElementById("randomPoint")) {
const randomPointRect = document.getElementById("randomPoint").getBoundingClientRect()
const dot = document.getElementById("0")
const dotRect = dot.getBoundingClientRect()
var overlap = !(dotRect.right < randomPointRect.left ||
dotRect.left > randomPointRect.right ||
dotRect.bottom < randomPointRect.top ||
dotRect.top > randomPointRect.bottom)
if(overlap) score++
if(!overlap) score = 0
document.body.removeChild(document.getElementById("randomPoint"))
}
const randomHeight = (Math.floor(Math.random() * (screenHeight - 100))) + 51
const randomWidth = (Math.floor(Math.random() * (screenHeight - 100))) + 51
const randomPoint = document.createElement("div")
randomPoint.id = "randomPoint"
randomPoint.classList.add("dot")
randomPoint.style.top = randomHeight + "px"
randomPoint.style.left = randomWidth + "px"
randomPoint.style.height = "2.5vh"
randomPoint.innerText = score
document.body.appendChild(randomPoint)
console.log(randomHeight)
console.log(randomWidth)
}, 2000);