bnb({
w: 540, h: 540,
numFrames: 120,
fps: 20,
record: true,
webgl: true,
preload: (s, g) => {
g.img = s.loadImage(`https://source.unsplash.com/featured?skyline,buildings,${Date.now()}`)
console.log(g.img.width)
g.rects = []
const cosT = s.cos(0) * 10
const sinT = s.sin(0) * 10
const prng = new PRNG(seed)
const divide = (x, y, w, h, step) => {
if (step > 0 && prng.rand(3 + step) > .5) {
let n = simplex.noise4D(x / 150, y / 150, cosT / (step ** 2), sinT / (step ** 2)) * .5 + .5
step--
if (prng.rand() < .5) {
divide(x, y, w * n, h, step)
divide(x + w * n, y, w * (1 - n), h, step)
} else {
divide(x, y, w, h * n, step)
divide(x, y + h * n, w, h * (1 - n), step)
}
}
else {
g.rects.push({
x: x,
y: y,
w: w,
h: h
})
}
}
divide(0, 0, g.w, g.h, 12)
},
draw: (s, t, g) => {
s.translate(-g.w/2, -g.h/2)
const cosT = s.cos(t * TAU) * 10
const sinT = s.sin(t * TAU) * 10
const prng = new PRNG(seed)
s.noStroke()
s.drawingContext.shadowColor = s.color(0, 0, 0, 45);
s.drawingContext.shadowBlur = 25;
let index = 0
const divide = (x, y, w, h, step) => {
s.drawingContext.shadowOffsetX = step * 2;
s.drawingContext.shadowOffsetY = step * 2;
if (step > 0 && prng.rand(3 + step) > .5) {
let n = simplex.noise4D(x / 150, y / 150, cosT / (step ** 2), sinT / (step ** 2)) * .5 + .5
step--
if (prng.rand() < .5) {
divide(x, y, w * n, h, step)
divide(x + w * n, y, w * (1 - n), h, step)
} else {
divide(x, y, w, h * n, step)
divide(x, y + h * n, w, h * (1 - n), step)
}
}
else {
const r = g.rects[index]
s.texture(g.img)
s.beginShape()
s.vertex(x, y, r.x/g.w * g.img.width, r.y/g.h * g.img.height)
s.vertex(x+w, y, r.x/g.w * g.img.width + r.w/g.w * g.img.width, r.y/g.h * g.img.height)
s.vertex(x+w, y+h, r.x/g.w * g.img.width + r.w/g.w * g.img.width, r.y/g.h * g.img.height + r.h/g.h * g.img.height)
s.vertex(x, y+h, r.x/g.w * g.img.width, r.y/g.h * g.img.height + r.h/g.h * g.img.height)
s.endShape(s.CLOSE)
index ++
}
}
divide(0, 0, g.w, g.h, 12)
}
})