Description
let spamText = "SPAM";
let fontList = ["Arial", "Helvetica", "Times", "Courier"];
let letters = ["SPAM", "Start", "Pumping", "Art", "Markets", "SPAM"];
let size;
let x = [];
let y = [];
let xSpeed = [];
let ySpeed = [];
let alphaValue = 0; //
let fadeInSpeed = 5; //
let fadeOutSpeed = 2; //
let fadingIn = true;
let letterBuffer;
let backgroundBuffer;
function setup() {
createCanvas(600, 600);
noStroke();
noiseDetail(2, 8);
letterBuffer = createGraphics(width, height);
letterBuffer.noStroke();
backgroundBuffer = createGraphics(width, height);
backgroundBuffer.noStroke();
for (let j = 0; j < 2; j++) {
for (let i = 0; i < letters.length; i++) {
x.push(width / 2 - 50 + i * 50);
y.push(height / 2);
xSpeed.push(random(-5, 5));
ySpeed.push(random(-5, 5));
}
}
}
function draw() {
if (fadingIn) {
alphaValue += fadeInSpeed;
if (alphaValue >= 255) {
alphaValue = 255;
fadingIn = false;
}
} else if (frameCount > 300) {
alphaValue -= fadeOutSpeed;
if (alphaValue <= 0) {
resetAnimation();
return;
}
}
createBackground();
createText();
tint(255, alphaValue); //
image(backgroundBuffer, 0, 0);
image(letterBuffer, 0, 0);
}
function createBackground() {
for (let i = 0; i < width; i += 5) {
for (let j = 0; j < height; j += 5) {
let n = noise(i * 0.02, j * 0.02, frameCount * 0.02) * 255;
let r = map(n, 0, 255, 255, 255);
let g = map(n, 0, 255, 80, 130);
let b = map(n, 0, 255, 100, 180);
backgroundBuffer.fill(r, g, b);
backgroundBuffer.rect(i, j, 5, 5);
}
}
}
function createText() {
for (let i = 0; i < x.length; i++) {
let letter = letters[i % letters.length];
let color = [random(255), random(255), random(255)];
letterBuffer.fill(color);
size = 10 + sin(frameCount / 20 + i) * 90;
letterBuffer.textSize(size);
letterBuffer.text(letter, x[i], y[i]);
xSpeed[i] += random(-0.2, 0.2);
ySpeed[i] += random(-0.2, 0.2);
x[i] += xSpeed[i];
y[i] += ySpeed[i];
if (x[i] > width || x[i] < 0) {
xSpeed[i] *= -1;
}
if (y[i] > height || y[i] < 0) {
ySpeed[i] *= -1;
}
}
}
function resetAnimation() {
alphaValue = 0;
frameCount = 0;
fadingIn = true;
backgroundBuffer.clear();
letterBuffer.clear();
createBackground();
}