p5(sketch => {
let graphic;
let font;
let pos = 0;
sketch.setup = function() {
sketch.frameRate(fr);
sketch.createCanvas(canvasWidth, canvasHeight);
graphic = sketch.createGraphics(canvasWidth, canvasHeight);
graphic.fill(textColor);
graphic.textSize(fontsize);
graphic.textFont('sans-serif');
graphic.textAlign(sketch.CENTER, sketch.CENTER);
graphic.text(words, canvasWidth / 2, canvasHeight / 2);
};
sketch.draw = function() {
sketch.background(bgColor);
for (let i = 0; i < tilesTall * tilesWide; i++) {
const row = Math.floor(i / tilesWide) * tileHeight;
const column = (i % tilesWide) * tileWidth;
let wave = pos / canvasHeight;
wave = easings[easing](wave);
const reverseWave = 1 - wave;
const sx = column;
const sy = row * wave;
const sw = tileWidth;
const sh = tileHeight * wave + canvasHeight * reverseWave;
const dx = column;
const dy = row;
const dw = tileWidth;
const dh = tileHeight;
sketch.copy(graphic, sx, sy, sw, sh, dx, dy, dw, dh);
}
sketch.mouseWheel = function(event) {
if (pos <= canvasHeight || event.delta < 0) pos += event.delta;
if (pos < 0) pos = 0;
};
};
})