This repository has been archived by the owner on Jun 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
matrix.js
99 lines (84 loc) · 2 KB
/
matrix.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
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
var streams = [];
var fadeInterval = 1.75;
var symbolSize = 22;
function setup() {
createCanvas(
window.innerWidth,
window.innerHeight
);
background(0);
var x = 0;
for (var i = 0; i <= width / symbolSize; i++) {
var stream = new Stream();
stream.generateSymbols(x, random(-2000, 0));
streams.push(stream);
x += symbolSize
}
textFont('Consolas');
textSize(symbolSize);
}
function draw() {
background(0, 200);
streams.forEach(function(stream) {
stream.render();
});
}
function Symbol(x, y, speed, first, opacity) {
this.x = x;
this.y = y;
this.value;
this.speed = speed;
this.first = first;
this.opacity = opacity;
this.switchInterval = round(random(2, 25));
this.setToRandomSymbol = function() {
var charType = round(random(0, 5));
if (frameCount % this.switchInterval == 0) {
if (charType > 1) {
this.value = String.fromCharCode(
0x30A0 + round(random(0, 96))
);
} else {
this.value = round(random(0,9));
}
}
}
this.matrix = function() {
this.y = (this.y >= height) ? 0 : this.y += this.speed;
}
}
function Stream() {
this.symbols = [];
this.totalSymbols = round(random(5, 30));
this.speed = random(2, 15);
this.generateSymbols = function(x, y) {
var opacity = 255;
var first = round(random(0, 4)) == 1;
for (var i =0; i <= this.totalSymbols; i++) {
symbol = new Symbol(
x,
y,
this.speed,
first,
opacity
);
symbol.setToRandomSymbol();
this.symbols.push(symbol);
opacity -= (255 / this.totalSymbols) / fadeInterval;
y -= symbolSize;
first = false;
}
}
this.render = function() {
this.symbols.forEach(function(symbol) {
if (symbol.first) {
fill(140, 255, 170, symbol.opacity);
} else {
fill(0, 255, 70, symbol.opacity);
}
text(symbol.value, symbol.x, symbol.y);
symbol.matrix();
symbol.setToRandomSymbol();
});
}
}