-
Notifications
You must be signed in to change notification settings - Fork 0
/
cupido.draft-3.dweet.js
40 lines (31 loc) · 1.04 KB
/
cupido.draft-3.dweet.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
el = c.getBoundingClientRect();
onmousemove = (e) => {
x.clearRect(0, 0, c.width, c.height);
hCW = c.width / 2;
hCH = c.height / 2;
cCenterX = el.left + (el.right - el.left) / 2;
cCenterY = el.top + (el.bottom - el.top) / 2;
mX = e.clientX - cCenterX;
mY = e.clientY - cCenterY;
scaleXLeft = cCenterX / hCW;
scaleXRight = (innerWidth - cCenterX) / hCW;
scaleYTop = cCenterY / hCH;
scaleYBottom = (innerHeight - cCenterY) / hCH;
mXAdjusted = mX * (mX < 0 ? scaleXLeft : scaleXRight);
mYAdjusted = mY * (mY < 0 ? scaleYTop : scaleYBottom);
hit = Math.round(mXAdjusted / 10) == 0 && Math.round(mYAdjusted / 10) == 0;
if (hit) {
x.fillText('💘', hCW, hCH);
} else {
bX =
mX < 0
? (e.clientX / cCenterX) * 960
: 1920 - ((innerWidth - e.clientX) / (innerWidth - cCenterX)) * 960;
bY =
mY < 0
? (e.clientY / cCenterY) * 540
: 1080 - ((innerHeight - e.clientY) / (innerHeight - cCenterY)) * 540;
x.fillText('🏹', bX, bY);
x.fillText('💖', hCW, hCH);
}
};