xxxxxxxxxx
// Starter sketch for this challenge:
// https://www.notion.so/neillzero/offset-a-3d-terrain-grid-with-perlin-noise-440a0bee9ff54bce82dad104a5e0bdc5
let vOffset = 5000
let hOffset = 500000
let dOffset = 600000
function setup() {
createCanvas(windowWidth, windowHeight, WEBGL);
// debugMode()
const cam = createCamera();
cam.setPosition(300, -200, 600)
cam.lookAt(0, 0, 0)
}
function decideColour(n) {
if (n > 0.75) {
return "white"
} else if (n > 0.65) {
return "gray"
} else if (n > 0.5) {
return "green"
} else if (n > 0.4) {
return "yellow"
} else if (n > 0.3) {
return "skyblue"
} else {
return "navy"
}
}
function draw() {
let noiseScale = 0.003
background('white')
orbitControl(5, 5, 0.2);
const gridHalfWidth = 40;
const cellSize = 10;
for (let gridX = -gridHalfWidth; gridX < gridHalfWidth; gridX++) {
for (let gridZ = -gridHalfWidth; gridZ < gridHalfWidth; gridZ++) {
const x = gridX * cellSize;
const z = gridZ * cellSize;
let n = noise(hOffset + x * noiseScale, dOffset + z * noiseScale); // Offsets are added to combatt symmetry
let y = 0
if (n < 0.4) {
let y = n * -100
}// why can't I use a for loop?
//const y = Math.max(n, 0.4) * -100; //height of each cell. change this to be based on perlin noise at x,z
push();
translate(x, y, z)
fill(decideColour(n))
box(cellSize, cellSize, cellSize);
pop()
}
}
}