-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.js
92 lines (78 loc) · 2.13 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
var symbolSize = 30;
var streams = [];
var backgroundColor = 0;
var canvasWidth = window.innerWidth;
var canvasHeight = window.innerHeight;
var minSymbolsSpeed = 6;
var maxSymbolsSpeed = 12;
var minStreamLenght = 5;
var maxStreamLenght = 30;
function setup(){
createCanvas(
canvasWidth,
canvasHeight
);
background(backgroundColor);
textSize(symbolSize);
var x = 0;
for (var i = 0; i<= width / symbolSize; i++){
var stream = new Stream();
stream.generateSymbols(x, random(-1000,0));
streams.push(stream);
x+=symbolSize;
}
}
function draw(){
background(backgroundColor, 180);
streams.forEach(function(stream){
stream.render();
});
}
function Symbol(x, y, speed, isFirst){
this.x = x;
this.y = y;
this.speed = speed;
this.switchInterval = round(random(2,20));
this.isFirst = isFirst;
this.value;
this.setToRandomSymbol = function(){
if(frameCount % this.switchInterval == 0){
this.value = String.fromCharCode(
0x30A0 + round(random(0,96))
);
}
}
this.moveDown = function(){
if(this.y >= height)
this.y = 0;
else
this.y += this.speed;
}
}
function Stream(){
this.symbols = [];
this.totalSymbols = round(random(minStreamLenght, maxStreamLenght));
this.speed = round(random(minSymbolsSpeed, maxSymbolsSpeed));
this.generateSymbols = function(x, y){
var first = round(random(0,4)) == 1;
for(var i = 0; i<= this.totalSymbols; i++)
{
var symbol = new Symbol(x, y, this.speed, first);
symbol.setToRandomSymbol();
this.symbols.push(symbol);
y -= symbolSize;
first = false;
}
}
this.render = function (){
this.symbols.forEach(function(symbol){
if(symbol.isFirst)
fill(180,255,180);
else
fill(0,255,70)
text(symbol.value, symbol.x, symbol.y);
symbol.moveDown();
symbol.setToRandomSymbol();
})
}
}