await visibility(), (() => {
const scene = new ln.Scene()
const getPaths = (cube, nx = 10, ny = 10, nz =10) => () => {
const paths = []
const { x: x1, y: y1, z: z1 } = cube.min
const { x: x2, y: y2, z: z2 } = cube.max
paths.push([new ln.Vector(x1, y1, z1), new ln.Vector(x1, y2, z1)])
paths.push([new ln.Vector(x1, y1, z1), new ln.Vector(x1, y1, z2)])
paths.push([new ln.Vector(x2, y2, z2), new ln.Vector(x1, y2, z2)])
paths.push([new ln.Vector(x2, y2, z2), new ln.Vector(x2, y1, z2)])
paths.push([new ln.Vector(x2, y2, z2), new ln.Vector(x2, y2, z1)])
paths.push([new ln.Vector(x1, y2, z1), new ln.Vector(x2, y2, z1)])
paths.push([new ln.Vector(x1, y2, z1), new ln.Vector(x1, y2, z2)])
paths.push([new ln.Vector(x1, y2, z2), new ln.Vector(x1, y1, z2)])
paths.push([new ln.Vector(x1, y1, z2), new ln.Vector(x2, y1, z2)])
for(let i = 1; i < nx; i++) {
const p = i / nx
const x = x1 + (x2 - x1) * p
paths.push([new ln.Vector(x, y1, z2), new ln.Vector(x, y2, z2)])
paths.push([new ln.Vector(x, y1, z1), new ln.Vector(x, y1, z2)])
paths.push([new ln.Vector(x, y2, z1), new ln.Vector(x, y2, z2)])
}
for(let i = 1; i < ny; i++) {
const p = i / ny
const y = y1 + (y2 - y1) * p
paths.push([new ln.Vector(x1, y, z2), new ln.Vector(x2, y, z2)])
paths.push([new ln.Vector(x1, y, z1), new ln.Vector(x1, y, z2)])
}
for(let i = 1; i < nz; i++) {
const p = i / nz
const z = z1 + (z2 - z1) * p
paths.push([new ln.Vector(x1, y2, z), new ln.Vector(x2, y2, z)])
paths.push([new ln.Vector(x1, y1, z), new ln.Vector(x1, y2, z)])
}
return paths
}
// create a cube at the center
let cube = new ln.Cube(new ln.Vector(-2, -2, -2), new ln.Vector(2, 2, 2))
cube.paths = getPaths(cube, 30, 30, 30)
scene.add(cube)
// let's add 200 randomly positioned boxes
for(let i = 0; i < 200; i ++) {
let length = randInt(1, 30)
let p = (randInt(30) + length/4) * coin() // pos on axis
let w = random(.08, 1.5)
let offset1 = random(1.9 - w/2) * coin()
let offset2 = random(1.9 - w/2) * coin()
let min, max
let axis = randInt(3)
if(axis === 0) { // x axis
min = new ln.Vector(p - length / 2, offset1 - w/2, offset2 - w/2)
max = new ln.Vector(p + length / 2, offset1 + w/2, offset2 + w/2)
}
else if(axis === 1) { // y axis
min = new ln.Vector(offset1 - w/2, p - length / 2, offset2 - w/2)
max = new ln.Vector(offset1 + w/2, p + length / 2, offset2 + w/2)
}
else { // z axis
min = new ln.Vector(offset1 - w/2, offset2 - w/2, p - length / 2)
max = new ln.Vector(offset1 + w/2, offset2 + w/2, p + length / 2)
}
const box = new ln.Cube(min, max)
const diffx = max.x - min.x
const diffy = max.y - min.y
const diffz = max.z - min.z
box.paths = getPaths(box, random(1, 15) * diffx | 0, random(1, 15) * diffy | 0, random(1, 15) * diffz | 0)
scene.add(box)
}
// render the scene
const eye = new ln.Vector(-28, 12, 8)
const center = new ln.Vector(-3, 0, 0)
const height = width / 21 * 29.7
const angle = Math.PI / 2. + .5
const up = new ln.Vector(-.3, 1.2, -.6).normalize()
// compute the paths to show
const paths = scene.render(eye, center, up, width, height, 40, 0.1, 150, 0.01)
// display the SVG
return svg`${ln.toSVG(paths, width, height)}`
})()