Created
January 4, 2021 23:29
-
-
Save 97997/987ac7ae1919d699d68fca63f28a0e11 to your computer and use it in GitHub Desktop.
872688659\js\main.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var symbolSize = 20; | |
var streams = []; | |
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; | |
} | |
textSize(symbolSize); | |
textFont("Microsoft YaHei") | |
strokeWeight(3); | |
} | |
function draw() { | |
background(0, 120); | |
streams.forEach(function (stream) { | |
stream.render(); | |
}); | |
} | |
function Symbol(x, y, speed, first) { | |
this.x = x; | |
this.y = y; | |
this.speed = speed; | |
this.value; | |
this.switchInterval = round(random(5, 20)); | |
this.first = first; | |
this.setToRandomSymbol = function() { | |
if (frameCount % this.switchInterval == 0) { | |
this.value = String.fromCharCode( | |
0x30A0 + round(random(0, 96)) | |
); | |
} | |
} | |
this.render = function() { | |
fill(0, 255, 70); | |
text(this.value, this.x, this.y); | |
this.rain(); | |
this.setToRandomSymbol(); | |
} | |
this.rain = function() { | |
if (this.y >= height) { | |
this.y = 0; | |
} else { | |
this.y += this.speed; | |
} | |
} | |
} | |
function Stream() { | |
this.symbols = []; | |
this.totalSymbols = round(random(10, 40)); | |
this.speed = random(1, 8); | |
this.generateSymbols = function(x, y) { | |
var first = round(random(4)) == 1; | |
for (var i = 0; i <= this.totalSymbols; i++) { | |
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.first) { | |
fill(180, 255, 180); | |
} else { | |
fill(0, 255, 70); | |
} | |
text(symbol.value, symbol.x, symbol.y); | |
symbol.rain(); | |
symbol.setToRandomSymbol(); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment