xxxxxxxxxx
/*
code scroll #genuary28 #genuary #genuary2528
Infinite Scroll.
https://openprocessing.org/sketch/2525484
#generativeart #creativecoding #p5js
*/
let pal;
let blocks, sze, num = 25;
function setup() {
createCanvas(S=min(windowWidth, windowHeight), S);
describe("coding blocks scrolling thru window")
frameRate(15);
noStroke();
sze = S / num;
pal = palettes[frameCount%palettes.length];
blocks = [];
}
function draw() {
background(32);
addBlock();
drawBlocks();
drawMsg("code scroll (epi) #genuary2528")
}
function addBlock() {
let indent = 0;
if (blocks.length > 0) {
indent = blocks[blocks.length-1][0].i;
if (random() < 0.2) {
indent = constrain(indent + 1*Math.sign(random()-0.5), 0, 5);
}
}
if (blocks.length === 0 || random()<0.3) {
// new line
blocks.push([{i: indent, c: ~~random(pal.length), l: ~~random(3, 11)}]);
} else {
// append
blocks[blocks.length-1].push({i: 0, c: ~~random(pal.length), l: ~~random(3, 11)});
}
while (blocks.length > num) blocks.shift();
}
function drawBlocks() {
let x = 0, y = 0;
for (let bl of blocks) {
x = 0;
for (let cd of bl) {
fill(pal[cd.c]);
if (cd.i) x += cd.i * sze;
rect(x, y, cd.l * sze, sze, sze/2);
x += (cd.l+1) * sze;
}
y += sze;
}
}
function drawMsg(msg) {
push();
blendMode(BLEND);
fill("black")
noStroke();
textAlign(LEFT, TOP)
text(msg, 1, 1)
fill("white")
noStroke();
textAlign(LEFT, TOP)
text(msg, 0, 0)
pop();
}
function mousePressed() {
if (mouseButton != RIGHT) setup();
}