bnb({
w: 540,
h: 540,
webgl: true,
numFrames: 160,
fps: 24,
samplesPerFrame: 12,
shutterAngle: 1,
chromaticAberration: .2,
record: true,
video: true,
globals: {
moves: array(12).map(i => ({
axis: ['x', 'y', 'z'][randInt(3)],
slice: i % 3,
angle: PI / 2 * randInt(1, 3) * coin()
}))
},
setup: (s, g) => {
s.frameRate(30)
},
draw: (s, time, g) => {
const n = g.moves.length
const index = time * n | 0
const duration = 1 / n
const move = g.moves[index]
const t = ease(linearstep(time, index * duration, (index + 1) * duration), 2)
s.background(0)
s.camera(0, -250, (s.height / 2) / s.tan(PI * 30 / 180), 0, 0, 0, 0, 1, 0);
s.fill(255)
s.stroke(0)
s.strokeWeight(5)
s.translate(0, 90, -200)
s.rotateY(PI/4)
const size = 140
let c = 0
for(let x = 0; x < 3; x ++) {
for(let y = 0; y < 3; y ++) {
for(let z = 0; z < 3; z ++) {
s.push()
if(move.axis === 'x' && x === move.slice) s.rotateX(t * move.angle)
if(move.axis === 'y' && y === move.slice) s.rotateY(t * move.angle)
if(move.axis === 'z' && z === move.slice) s.rotateZ(t * move.angle)
s.translate((x - 1.5) * size, (y - 1.5) * size, (z - 1.5) * size)
s.translate(size / 2, size / 2, size / 2)
s.box(size)
s.pop()
c++
}
}
}
}
})