xxxxxxxxxx
106
p5.prototype.getSymbol = function(){
return String.fromCharCode(
0x30A0 + round(random(0,96)) //all but 77
);
}
class Matrix{
constructor(x1,y1,x2,y2){
this.chains = [];
this.symbolSize = 20;
this.x1 = x1;
this.y1 = y1;
this.x2 = x2;
this.y2 = y2;
for(let i = this.x1; i < this.x1+this.x2; i+= this.symbolSize){
if(round(random(1,5)) != 1){
append(this.chains, new Chain(i,this.y1,this.y2,this.symbolSize));
}
}
}
run(){
stroke(180);
fill(0,90);
rect(this.x1,this.y1,this.x2,this.y2);
for(let c of this.chains){
c.render();
}
}
}
class Character{
constructor(x,y,s,f,symbolSize,y1,y2){
this.pos = createVector(x,y);
this.size = symbolSize;
this.speed = s;
this.interval = round(random(2,7));
this.first = f;
this.y1 = y1;
this.y2 = y2;
this.symbolSize = symbolSize;
//clean up
this.symbol = getSymbol();
}
update(){
if(this.pos.y <= this.y1+this.y2-2){
this.pos.y += this.speed;
}else{
this.pos.y = this.y1+18;
}
if(frameCount % this.interval == 0){
this.symbol = getSymbol();
}
}
render(){
if(this.pos.y > this.y1){
noStroke();
if(this.first){
fill(180,255,180);
}else{
fill(0,255,70);
}
textSize(this.size);
text(this.symbol,this.pos.x,this.pos.y)
}
}
}
class Chain{
constructor(x,y1,y2,symbolSize){
this.size = round(random(5,10));
this.pos = createVector(x,random(y1+this.size*symbolSize,y2));
this.speed = random(2,3);
this.symbols = [];
let first = false;
for(let i = 0; i <= this.size; i++){
if(i == 0 && round(random(1,3)) == 1){
first = true;
}else{
first = false;
}
append(this.symbols,new Character(
this.pos.x,
this.pos.y-i*symbolSize,
this.speed,
first,symbolSize,y1,y2
));
}
}
render(){
for(let s of this.symbols){
s.update();
s.render();
}
}
}