This repository has been archived by the owner on Aug 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathemoji.js
50 lines (43 loc) · 1.38 KB
/
emoji.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
(function() {
const addInterval = 36;
const active = [];
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
function Emoji(type) {
this.x = Math.floor(Math.random() * window.innerWidth) - 30;
this.y = 0;
this.emoji = type;
this.acceleration = 0.5;
this.currentTick = 0;
this.height = 0;
this.fall = function() {
const velocity = this.acceleration * this.currentTick;
this.y = velocity * velocity;
ctx.fillText(this.emoji, this.x, this.y);
this.currentTick++;
return this.y <= canvas.height;
}
}
function run() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
ctx.font = '80px Arial';
ctx.fillStyle = 'white';
active = active.filter(e => e.fall());
}
function bg() {
canvas.style.backgroundColor = 'rgb('+[
Math.floor(Math.random()*256),
Math.floor(Math.random()*256),
Math.floor(Math.random()*256)
].join(',')+')';
}
function add() {
active.push(new Emoji(ALL_EMOJIS[Math.floor(Math.random() * ALL_EMOJIS.length)]));
setTimeout(add, addInterval);
}
add();
setInterval(run, 18);
bg();
})();