xxxxxxxxxx
106
let terrain;
let cols, rows;
let w = 45;
let flying = 0;
let t = 0;
let t2 = 10000;
function setup() {
createCanvas(windowWidth, windowHeight, WEBGL);
cols = floor(width / w);
rows = floor(height / w);
terrain = new Terrain(cols, rows);
// Set the camera position and orientation
let camX = width/3;
let camY = height / 2; // Adjust this value for the desired side view
let camZ = (height / 2) / tan(PI / 5); // Adjust this value for the desired zoom
camera(camX, camY, camZ, 0, 0, 0, 0, 1, 0);
}
function draw() {
background(255);
// Center the sketch on the canvas
translate(-width / 2, -height / 2);
terrain.update();
terrain.display();
flying -= 0.01;
for(let i=0; i<30; i++){
line(x1(t+i), y1(t+i),x2(t+i), y2(t+i));
point(x1(t+i), y1(t+i));
point(x2(t+i), y2(t+i));
// line(x3(t+i), y3(t+i),x4(t+i), y4(t+i));
// point(x3(t+i), y3(t+i));
// point(x4(t+i), y4(t+i));
t+=0.005;
}
}
class Terrain {
constructor(cols, rows) {
this.cols = cols;
this.rows = rows;
this.w = w;
this.terrain = [];
}
update() {
let yoff = flying;
for (let y = 0; y < this.rows; y++) {
let xoff = 0;
this.terrain[y] = [];
for (let x = 0; x < this.cols; x++) {
this.terrain[y][x] = map(noise(xoff, yoff), 0, 1, -200, 200);
xoff += 0.3;
}
yoff += 0.3;
}
}
display() {
stroke(0);
noFill();
for (let y = 0; y < this.rows - 1; y++) {
beginShape(TRIANGLE_STRIP);
for (let x = 0; x < this.cols; x++) {
vertex(x * this.w, y * this.w, this.terrain[y][x]);
vertex(x * this.w, (y + 1) * this.w, this.terrain[y + 1][x]);
}
endShape();
}
}
}
function x1(t){
return sin(-t/10)*100 + cos(-t/5)*200;
}
function y1(t){
return cos(-t/10)*1000;
}
function x2(t){
return sin(-t/10)*2000 + cos(t)*20;
}
function y2(t){
return cos(t/12)*20;
}
function x3(t2){
return sin(t2/10)*100 + cos(t2/5)*200;
}
function y3(t2){
return cos(t2/10)*1000;
}
function x4(t){
return sin(t2/10)*2000 + cos(-t2)*20;
}
function y4(t2){
return cos(-t2/12)*20;
}