This repository has been archived by the owner on Mar 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
163 lines (148 loc) · 4.92 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<!DOCTYPE html>
<html prefix="og: http://ogp.me/ns#">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<meta name="description" content="Starry Night, inspired by the original screen saver known from Norton Commander">
<meta name="copyright" content="Copyright (c) 2021 Gabor Bata">
<meta name="twitter:card" content="summary">
<meta name="twitter:site" content="@gabor_bata">
<meta name="twitter:creator" content="@gabor_bata">
<meta property="og:title" content="Starry Night">
<meta property="og:description" content="Starry Night, inspired by the original screen saver known from Norton Commander">
<meta property="og:type" content="product">
<meta property="og:url" content="https://gaborbata.github.io/starry-night/">
<meta property="og:image" content="https://gaborbata.github.io/starry-night/starry-night.png">
<title>✨ Starry Night</title>
<style type="text/css">
body {
background-color: #000;
color: #ccc;
margin: 0;
padding: 0;
}
#wrapper {
display: table;
height: 100%;
position: absolute;
width: 100%;
}
#container {
display: table-cell;
}
#footer {
bottom: 0;
height: 150px;
left: 0;
position: fixed;
width: 100%;
z-index: 1;
}
#dialog {
background-color: #00c;
border: 4px double #0cc;
font-family: 'Lucida Console', monospace;
font-size: 14px;
text-align: center;
margin: 20px auto;
padding: 20px;
width: 70%;
}
.star {
background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADwAAAAKCAMAAADfAc3wAAAACVBMVEUAAACHiYb////0rNC2AAAAP0lEQVR42mMgDzAxka6FVM1MIABnQmkIwqcJSTOmMQitjIwYzsHUwgQBEBaYwKsZv834/UrQzzQLbQLuohQAAAB7AM2+S2csAAAAAElFTkSuQmCC');
background-size: 120px 20px;
height: 20px;
image-rendering: pixelated;
position: absolute;
width: 20px;
}
.star-1 {
background-position: 0 0;
}
.star-2 {
background-position: -20px 0;
}
.star-3 {
background-position: -40px 0;
}
.star-4 {
background-position: -60px 0;
}
.star-5 {
background-position: -80px 0;
}
.star-6 {
background-position: -100px 0;
}
</style>
<div id="footer">
<div id="dialog">
Starry Night, inspired by the original screen saver known from Norton Commander<br>
Copyright (c) 2021 Gabor Bata
</div>
</div>
<div id="wrapper">
<div id="container"></div>
</div>
<script>
{
const STAR_DISAPPEAR = 2, STAR_BLOW_UP = 6, STARS = new Map(), TICK = 150;
let width, height, intervalId = null;
function init() {
intervalId != null && clearInterval(intervalId);
const container = document.querySelector('#container');
STARS.forEach(star => container.removeChild(star.el));
STARS.clear();
width = Math.floor(container.clientWidth / 20);
height = Math.floor(container.clientHeight / 30);
const numOfStars = Math.max(Math.floor(width * height / 60.0), width * height > 12 ? 12 : 0);
while (STARS.size < numOfStars) {
const el = document.createElement('div');
el.classList.add('star');
reset(el);
container.appendChild(el);
}
intervalId = setInterval(animate, TICK);
}
function animate() {
const deadStars = [];
STARS.forEach((star, id) => {
if (star.lifeTime > 0) {
star.lifeTime -= TICK;
} else {
if (star.animIdx < star.animLen) {
star.el.classList.replace(`star-${star.animIdx}`, `star-${++star.animIdx}`);
} else {
deadStars.push(id);
}
}
});
deadStars.forEach(id => {
const el = STARS.get(id).el;
STARS.delete(id);
reset(el);
});
}
function reset(el) {
let x, y, id;
do {
x = Math.floor(Math.random() * width);
y = Math.floor(Math.random() * height);
id = `${x}-${y}`;
} while (STARS.has(id));
el.style.left = `${x * 20}px`;
el.style.top = `${y * 30 + 5}px`;
el.classList.remove(`star-${STAR_DISAPPEAR}`, `star-${STAR_BLOW_UP}`);
el.classList.add('star-1');
STARS.set(id, {
el: el,
lifeTime: Math.floor(Math.random() * 8000) + 2000,
animLen: Math.random() > 0.2 ? STAR_DISAPPEAR : STAR_BLOW_UP,
animIdx: 1
});
}
init();
window.addEventListener('resize', init);
setTimeout(() => document.querySelector('#footer').style.display = 'none', 8000);
}
</script>
</html>