-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
33 lines (24 loc) · 841 Bytes
/
app.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
document.addEventListener('mousemove', (e) => {
console.log(e)
const mouseX = e.clientX;
const mouseY = e.clientY;
const anchor = document.getElementById('anchor')
const rekt = anchor.getBoundingClientRect();
const anchorX = rekt.left + rekt.width/2;
const anchorY = rekt.top + rekt.height/2;
const angleDeg = angle(mouseX, mouseY, anchorX, anchorY)
console.log(angleDeg)
const eyes =document.querySelectorAll('.eye')
eyes.forEach(eye => {
eye.style.transform = `rotate(${90 + angleDeg}deg)`; //eye rotation
//color change
anchor.style.filter = `hue-rotate(${angleDeg}deg)`;
});
})
function angle(cx, cy, ex, ey){
const dy = ey - cy;
const dx = ex - cx;
const rad = Math.atan2(dy, dx);
const deg = rad * 180 / Math.PI;
return deg;
}