xxxxxxxxxx
let geom
let blurRenderer
function setup() {
createCanvas(windowWidth, windowHeight, WEBGL)
blurRenderer = createGaussianBlurRenderer()
blurRenderer.setIntensity(0.08)
blurRenderer.setSamples(20)
blurRenderer.setDof(50)
const floor = height/2
const forest = []
forest.push(() => {
translate(0, floor)
rotateX(PI/2)
fill('#61626A')
plane(width*16, width*16)
})
for (let i = 0; i < 400; i++) {
let x = randomGaussian(0, 1/3) * 4 * width
let z = randomGaussian(0, 1/3) * 4 * width
let d = Math.hypot(x, z)
if (d < 200) {
x = x / d * 200
z = z / d * 200
}
const h = height*0.5 + random(-1,1)*height*0.02
const branches = [{
x,
y: floor,
z,
r: width * 0.01,
h
}]
const n = round(random(20))
for (let i = 0; i < n; i++) {
const parent = random(branches)
const off = random([{ x: -1, z: 0 }, { x: 1, z: 0 }, { x: 0, z: -1 }, { x: 0, z: 1 }])
const y = random(parent.y, floor - h)
branches.push({
parent,
x: parent.x + off.x * width*0.05,
z: parent.z + off.z * width*0.05,
r: parent.r * 0.8,
y,
h: (y - (floor - h)),
})
}
forest.push(() => {
for (const branch of branches) {
fill('#BFB9AC')
if (branch.parent) {
push()
translate(
(branch.x + branch.parent.x)/2,
branch.y,
(branch.z + branch.parent.z)/2
)
box(
max(abs(branch.x - branch.parent.x), 0) + branch.r,
branch.r,
max(abs(branch.z - branch.parent.z), 0) + branch.r,
)
pop()
}
push()
translate(branch.x, branch.y - branch.h/2, branch.z)
box(branch.r, branch.h, branch.r)
translate(0, -branch.h/2, 0)
fill('#4F8572')
box(branch.r*8, width * 0.05, branch.r*8)
pop()
}
})
}
geom = buildGeometry(() => {
noStroke()
for (const drawObj of forest) {
push()
drawObj()
pop()
}
})
}
function draw() {
clear()
blurRenderer.draw(() => {
background('#F1D2A6')
// orbitControl()
ambientLight('#3657A4')
// spotLight(color(255), 0, -height, 0, 0, 1, 0, PI*0.5)
pointLight(0, 100, 255, 0, -height, -width)
directionalLight(255, 255, 255, -0.4, 0, 1)
directionalLight(255, 255, 255, 0.4, 0, 1)
directionalLight(255, 255, 255, 0, -0.4, 1)
directionalLight(255, 255, 255, 0, 0.4, 1)
camera(0, height*0.4, 0, 0, 0, -800)
push()
translate(0, -height*0.1, -400)
blurRenderer.focusHere()
pop()
rotateY(millis()*0.0001)
model(geom)
})
}