xxxxxxxxxx
122
const DROPPER_COUNT = 50;
const boldMode = false;
const debugText = false;
const fullSize = true;
const charStr = '012345789Z:・."=*+-<>¦|_/\\';
let symbols = [];
let chars = [];
let droppers = [];
let lifespan = [];
let colors = [];
let charWidth;
let charHeight;
let charSize = 16;
function setup() {
if (fullSize)
createCanvas(window.innerWidth, window.innerHeight);
else
createCanvas(412, 412);
colorMode(HSL, 360, 255, 100);
noStroke();
textSize(charSize);
textAlign(CENTER);
textFont('monospace');
if (boldMode)
textStyle(BOLD);
charWidth = round(width / charSize);
charHeight = round(height / charSize + 1);
generateSymbols();
for (let y = 0; y < charHeight; y++) {
for (let x = 0; x < charWidth; x++) {
let c = randomCode();
chars.push(c);
lifespan.push(0);
colors.push(0);
}
}
for (let i = 0; i < charWidth * 1.5; i++) {
droppers.push(new Dropper(
round(random(charWidth)),
round(random(charHeight))
));
}
}
function draw() {
background(0);
translate(charSize / 2, 0);
for (let y = 0; y < charHeight; y++) {
let yp = y * charSize;
for (let x = 0; x < charWidth; x++) {
let i = x + y * charWidth;
if (random() < 0.05)
chars[i] = randomCode();
let ls = lifespan[i];
if (ls > 0) {
lifespan[i] -= 2;
if (lifespan[i] < 50)
colors[i] = lifespan[i];
fill(140, 255, colors[i]);
text(chars[i], x * charSize, yp);
}
}
}
for (let i = 0; i < droppers.length; i++) {
let d = droppers[i];
let py = floor(d.y);
d.y += d.speed;
if (d.y > charHeight) {
d.y = 0;
// d.x = floor(random(charWidth));
}
let ry = floor(d.y);
if (ry - py >= 1) {
let previ = d.x + py * charWidth;
let newi = d.x + ry * charWidth;
lifespan[previ] = 80;
colors[previ] = 50;
lifespan[newi] = 100;
colors[newi] = 100;
}
}
if (debugText) {
fill(255);
text(frameRate(), 12, 12);
}
}
function Dropper(x, y) {
this.x = x;
this.y = y;
this.speed = 0.5;
this.lifespan = 100;
}
function generateSymbols() {
for (let i = 0; i < 96; i++)
symbols.push(String.fromCharCode(0x30A0 + i));
// for (let i = 0; i < 10; i++)
// symbols.push(i);
symbols.push(charStr.split(''));
}
function randomCode() {
// return String.fromCharCode(0x30A0 + round(random(96)));
return symbols[floor(random(symbols.length))];
}