xxxxxxxxxx
document.oncontextmenu =()=> false;
let cols, rows;
let scl = 10;
let w = 800;
let h = 800;
let terrain = [];
function setup() {
pixelDensity(2);
createCanvas(w, h, WEBGL);
setAttributes('antialias', true);
cols = w / scl;
rows = h / scl;
var easy=createEasyCam();
let state = {
distance : -1000, // scalar
center : [0, 0, 0], // vector
rotation : [random(500,1500),
random(500,1500),
random(500,1500),
random(50,150)], // quaternion
};
easy.setState(state, 5000); // animate to state over the period of 1 second
//easy.setViewport([0,0,windowWidth, windowHeight]);
for (let x = 0; x < cols; x++) {
terrain[x] = [];
for (let y = 0; y < rows; y++) {
terrain[x][y] = 0;
}
}
}
function draw() {
perspective(60 * PI/180, width/height, 1, 5000);
noiseSeed(50);
randomSeed(50);
background(30);
lights();
let upColors = [
color('#f94144'),
color('#f3722c'),
color('#f8961e'),
color('#f9c74f'),
color('#90be6d'),
color('#43aa8b'),
color('#577590')
];
push();
translate(-400,-400,0);
for (let x = 0; x < cols - 1; x++) {
beginShape(TRIANGLE_FAN);
for (let y = 0; y < rows; y++) {
let index = floor(map(terrain[x][y], -w/3, h/3, 0, upColors.length));
fill(upColors[index]);
stroke("#0466c8");
vertex(y * scl, (x) * scl, terrain[x][y]);
vertex(x * scl+scl, (y + 1) * scl, terrain[x][y-1]);
}
endShape();
}
pop();
noiseDetail(3, 0.66);
let yoff = 0;
for (let y = 0; y < rows; y++) {
let xoff = 0;
for (let x = 0; x < cols; x++) {
terrain[x][y] = map(noise(xoff, yoff), 0, 1, -300, 300);
xoff += 0.1;
}
yoff += 0.01;
}
}
function keyTyped() {
if (key === "s" || key === "S") {
saveCanvas("map-cadre_1-2_a-" + floor(random(100)), "png");
}
}