xxxxxxxxxx
let tower
let cube
let basket
let catBase
function setup() {
createCanvas(windowWidth, windowHeight, WEBGL)
cube = csg(() => {
box(200, 200, 200)
}).subtract(() => {
box(190, 190, 190)
}).subtract(() => {
rotateX(PI/2)
cylinder(80, 300)
}).subtract(() => {
rotateY(PI/2)
rotateX(PI/2)
cylinder(80, 300)
}).done()
cube.clearColors()
basket = csg(() => {
sphere(100)
}).subtract(() => {
translate(0, -100)
box(200, 200, 200)
}).subtract(() => {
translate(0, -10)
sphere(100)
}).done()
basket.clearColors()
catBase = csg(() => {
sphere(80)
}).subtract(() => {
translate(0, 100)
box(200, 200, 200)
}).done()
catBase.clearColors()
}
let base
function makeTower() {
if (tower) {
freeGeometry(tower)
}
tower = buildGeometry(() => {
new Structure().generate()
})
tower.normalize()
// tower.clearColors()
base = max(tower.vertices.map((v) => v.y))
}
let scene = -1
function draw() {
const nextScene = floor(millis() / 5000)
if (scene !== nextScene) {
scene = nextScene
makeTower()
}
background(scene % 2 === 0 ? '#CAEBCF' : '#D7E8F3')
noStroke()
scale(2.5 * min(width, height) / 800)
rotateX(PI * -0.1)
rotateY(millis() * 0.0002)
push()
fill(255)
directionalLight(150, 150, 150, 0, 1, -0.1)
directionalLight(100, 100, 100, 0.2, 0, -1)
ambientLight(100)
model(tower)
pop()
// push()
// translate(0, base, 0)
// rotateX(PI/2)
// fill(bgColor)
// plane(800, 800)
// pop()
}