createCanvas(windowWidth, windowHeight, WEBGL);
background(100, 160, 140);
for (let i = 0; i < treeCount; i++) {
trees.add(round(random(worldSize)) + worldSize * round(random(worldSize)));
(-boxSize * worldSize) / 2,
(boxSize * worldSize) / 2,
(-boxSize * worldSize) / 2
for (let z = 0; z < worldSize; z++) {
for (let y = 0; y < worldSize; y++) {
checkBoundaryAndDraw(i, y, z);
function checkBoundaryAndDraw(x, y, z) {
drawBlock(worldSize - x, y, z, calcColor(worldSize - x, y, z));
function getHeight(x, z) {
return map(noise(x / 20, z / 20), 0, 1, worldSize / 4, worldSize);
function calcColor(x, y, z) {
const h = getHeight(x, z);
trees.delete(x + worldSize * z);
return color(0, 20, 100 + y * 4, 170);
} else if (trees.has(x + worldSize * z)) {
return color(150, 130, 50);
if (noise(x / 5 + 2314, z / 5 + 0123, y / 5 + 1483) > 0.6) {
if (noise(x / 10 + 31053, z / 10 + 41534, y / 10 + 13532) > 0.7) {
return color(180 + y * 4, 0, 0);
if (y < 8 && random() > 0.999) {
return color(100, 200, 255);
if (y < noise(x + 300, z + 300) * 5 + 1) {
return color(200, 200, 0);
return color(20, 100 + y * 3, 20);
if (h - noise(x - 320, z - 300) * 5 - 5 < y) {
return color(150, 130, 50);
function drawBlock(x, y, z, c) {
translate(x * boxSize, -y * boxSize, z * boxSize);