-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.html
86 lines (80 loc) · 3.41 KB
/
index.html
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<html>
<head>
<style>
html {
width: 100%;
background: #000;
overflow: hidden;
}
body {
width: 100%;
transform: translateX(-2.5px);
}
img {
position: absolute;
user-select: none;
}
</style>
</head>
<body>
<img id="BODY" src="Body.png">
<img id="EYES" src="Eyes.png">
<script>
const BODY = document.getElementById("BODY");
const EYES = document.getElementById("EYES");
const heightScale = window.innerWidth / window.innerHeight;
const sleepyWaitTime = 1000 * 60 * 12;
var sleepyTime = false;
var sleepyTimeDate = Date.now() + sleepyWaitTime;
var mouseX = false, mouseY = false;
document.addEventListener("mousemove", (e) => {
mouseX = e.pageX;
mouseY = e.pageY;
sleepyTimeDate = Date.now() + sleepyWaitTime;
if(sleepyTime) {
EYES.src = "Eyes.png";
sleepyTime = false;
}
});
function update() {
let curTime = Date.now();
if(curTime > sleepyTimeDate) {
sleepyTime = true;
EYES.src = "EyesClosed.png"
}
var bobbingHeight = 60 * Math.sin(Math.PI * curTime / 5000);
let x = mouseX === false ? window.innerWidth / 2 : mouseX;
let y = mouseY === false ? window.innerHeight / 2 : mouseY;
BODY.style['transform'] = `translate(${
window.innerWidth / 2 + (x - window.innerWidth / 2) / 25 - BODY.offsetWidth / 2 + "px"
}, ${
window.innerHeight / 2 + heightScale * (y - window.innerHeight / 2) / 25 - BODY.offsetHeight / 2 + bobbingHeight + "px"
})`;
EYES.style['transform'] = `translate(${
window.innerWidth / 2 + (x - window.innerWidth / 2) / 22 - BODY.offsetWidth / 2 + "px"
}, ${
window.innerHeight / 2 + heightScale * (y - window.innerHeight / 2) / 22 - BODY.offsetHeight / 2 + bobbingHeight + "px"
})`;
}
setInterval(update, 1.0 / 240.0);
function eyeLoop() {
setTimeout(function() {
if(!sleepyTime) {
EYES.src = "EyesClosed.png";
}
setTimeout(function() {
if(!sleepyTime) {
EYES.src = "Eyes.png";
}
eyeLoop();
}, 1000 * (0.33 + 1 * Math.random()))
}, 10000 * (0.5 + 1.75 * Math.random()));
}
eyeLoop();
setTimeout(function() {
BODY.style['transform'] = `translate(${window.innerWidth / 2 - BODY.offsetWidth / 2 + "px"}, ${window.innerHeight / 2 - BODY.offsetHeight / 2 + "px"})`;
EYES.style['transform'] = `translate(${window.innerWidth / 2 - EYES.offsetWidth / 2 + "px"}, ${window.innerHeight / 2 - EYES.offsetHeight / 2 + "px"})`;
}, 100);
</script>
</body>
</html>