-
Notifications
You must be signed in to change notification settings - Fork 2
/
canvasScript.js
62 lines (39 loc) · 1.22 KB
/
canvasScript.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
51
52
53
54
55
56
57
58
59
60
61
62
// https://codepen.io/yaclive/pen/EayLYO
// Initialising the canvas
function getRandomInt(max) {
return Math.floor(Math.random() * max);
}
var canvas = document.querySelector("canvas"),
ctx = canvas.getContext("2d");
// Setting the width and height of the canvas
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
// Setting up the letters
var letters = "exabyte".split("")
// Setting up the columns
var fontSize = 10,
columns = canvas.width / fontSize;
// Setting up the drops
var drops = [];
for (var i = 0; i < columns; i++) {
drops[i] = getRandomInt(1000);
}
var count = 0;
// Setting up the draw function
function draw() {
ctx.fillStyle = "rgba(174, 52, 68, 0.1)";
ctx.fillRect(0, 0, canvas.width, canvas.height);
for (var i = 0; i < drops.length; i++) {
var text = letters[count];
ctx.fillStyle = "rgba(255, 255, 255, 0.9)";
ctx.font = "10px DotGothic16"
ctx.fillText(text, i * fontSize, drops[i] * fontSize);
drops[i]++;
if (drops[i] * fontSize > canvas.height && Math.random() > 0.95) {
drops[i] = 0;
}
}
count = (count + 1) % letters.length;
}
// Loop the animation
setInterval(draw, 100);