This repository has been archived by the owner on Oct 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
cmatrix.html
70 lines (64 loc) · 2.24 KB
/
cmatrix.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
<!DOCTYPE html>
<html>
<head>
<title>C matrix</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<style>
body {
margin: 0;
padding: 0;
background-color: black;
}
canvas {
position: fixed;
z-index: -1;
display: inline-block;
box-sizing: inherit;
}
</style>
<body>
<canvas id="c"></canvas>
<script type="text/javascript">
//hiding nav bar function
var ele = document.getElementsByClassName("navigation__link");
for (var i = 0; i < ele.length; i++) {
ele[i].style.display = "none";
}
var c = document.getElementById("c");
var ctx = c.getContext("2d");
c.height = window.innerHeight;
c.width = window.innerWidth;
//chinese characters - taken from the unicode charset
var chinese = "hacktoberfest2018;hacktoberfest2018;hacktoberfest2018;";
//converting the string into an array of single characters
chinese = chinese.split("");
var font_size = 10;
var columns = c.width / font_size; //number of columns for the rain
//an array of drops - one per column
var drops = [];
for (var x = 0; x < columns; x++)
drops[x] = 1;
//drawing the characters
function draw() {
ctx.fillStyle = "rgba(0, 0, 0, 0.05)";
ctx.fillRect(0, 0, c.width, c.height);
ctx.fillStyle = "#e3e4e5"; //green text
ctx.font = font_size + "px arial";
//looping over drops
for (var i = 0; i < drops.length; i++) {
var text = chinese[Math.floor(Math.random() * chinese.length)];
//x = i*font_size, y = value of drops[i]*font_size
ctx.fillText(text, i * font_size, drops[i] * font_size);
//sending the drop back to the top randomly after it has crossed the screen
//adding a randomness to the reset to make the drops scattered on the Y axis
if (drops[i] * font_size > c.height && Math.random() > 0.975) {
drops[i] = 0;
}
drops[i]++;
}
}
setInterval(draw, 60);
</script>
</body>
</html>