-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.js
104 lines (90 loc) · 2.52 KB
/
sketch.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
100
101
102
103
104
//by Emily Xie
var streams = [];
var fadeInterval = 1.4;
var symbolSize = 24;
function setup() {
let canvas = document.getElementById('cnv')
let cnv = createCanvas(
windowWidth, windowHeight);
cnv.parent(canvas)
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);
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) {
// set it to Katakana
this.value = String.fromCharCode(
0x30A0 + round(random(0, 96))
);
} else {
// set it to numeric
this.value = round(random(0, 9));
}
}
}
this.rain = function () {
this.y = (this.y >= height) ? 0 : this.y += this.speed;
}
}
function windowResized() {
resizeCanvas(window.innerWidth, window.innerHeight);
}
function Stream() {
this.symbols = [];
this.totalSymbols = round(random(5, 35));
this.speed = random(5, 22);
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.rain();
symbol.setToRandomSymbol();
});
}
}