render = bnb({
w, h,
fps: 20,
record: true,
video: true,
setup: (s, g) => {
const prng = new PRNG(prngSeed)
class Slash {
constructor(x, y) {
this.a = PVector(x, y)
this.b = PVector(7 * step * (prng.rand(9) < 5 ? -1 : 1), 7 * step * (prng.rand(9) < 5 ? -1 : 1)).add(this.a)
if(this.b.x < step || this.b.x > (n - 1) * step) this.b.subX(this.a.x).multX(-1).addX(this.a.x)
if(this.b.y < step || this.b.y > (n - 1) * step) this.b.subY(this.a.y).multY(-1).addY(this.a.y)
this.dir = [PVector(1, 0), PVector(0, 1)][prng.rand(0, 1)].mult(prng.rand(5, 29))
this.offset = prng.rand(1000)/1000
this.color = palette[prng.rand(1, palette.length - 1)]
}
display(s, t) {
if((t + this.offset) % 1 > .65) return;
const A = PVector.lerp(this.a, this.b, ease(linearstep((t + this.offset) % 1, 0, .3), 3.5))
const B = PVector.lerp(this.a, this.b, ease(linearstep((t + this.offset) % 1, .4, .7), 3.5))
s.noFill()
s.stroke(0)
s.strokeWeight(0.5)
this.shape(s, A, B)
s.noStroke()
s.fill(this.color)
this.shape(s, A, B)
}
shape(s, A, B) {
s.quad(
A.x - this.dir.x, A.y - this.dir.y,
A.x + this.dir.x, A.y + this.dir.y,
B.x + this.dir.x, B.y + this.dir.y,
B.x - this.dir.x, B.y - this.dir.y
)
s.quad(
(w - margin * 2) - (A.x - this.dir.x), A.y - this.dir.y,
(w - margin * 2) - (A.x + this.dir.x), A.y + this.dir.y,
(w - margin * 2) - (B.x + this.dir.x), B.y + this.dir.y,
(w - margin * 2) - (B.x - this.dir.x), B.y - this.dir.y
)
}
}
g.slashes = array(50).map(i => new Slash(prng.rand(1, n - 2) * step, prng.rand(1, n - 2) * step))
},
draw: (s, t, g) => {
s.background(palette[0])
s.translate(margin, margin)
s.push()
s.drawingContext.globalAlpha = 0.6
s.noStroke()
s.fill(255)
s.rectMode(s.CENTER)
for(let x = 0; x <= s.width - (margin * 2); x += step) {
for(let y = 0; y <= s.height - (margin * 2); y += step) {
s.push()
s.translate(x, y)
if(x % 125 === 0 && y % 125 === 0) {
s.rotate(linearstep(0.2, 0.5, t) * s.PI)
s.rect(0, 0, 8, 1)
s.rect(0, 0, 1, 8)
}
else s.rect(0, 0, 1, 1)
s.pop()
}
}
s.pop()
g.slashes.forEach(slash => slash.display(s, t))
}
})