// Cloned by Nithin Sai K J on 21 Sep 2023 from World "One Cube World (P5)" by Starter user
// Please leave this clone trail here.
const objectsize = 200; // size of object
const anglechange = 0.01; // how much the rotate angle changes each step
var angle = 0; // rotate angle starts at 0
var img;
var cols, rows;
var scl = 20;
var w = ABWorld.fullwidth();
var h = 1600;
var flying = 0;
var terrain;
function preload()
{
img = loadImage ( '/uploads/nithinsai/world1.jpg' );
}
function setup()
{
createCanvas ( ABWorld.fullwidth(), ABWorld.fullheight(), WEBGL );
cols = w / scl;
rows = h / scl;
terrain = create2DArray(cols, rows);
rectMode(CENTER);
}
function draw()
{
background(0);
noFill();
stroke(255);
texture(img);
// rotateX(angle);
// rotateY(angle);
// rotateZ(angle);
box(objectsize);
angle = angle + anglechange;
// rotateX(0);
// rotateY(0);
// rotateZ(0);
flying -= 0.1;
var yoff = flying;
for (let y = 0; y < rows; y++) {
var xoff = 0;
for (let x = 0; x < cols; x++) {
terrain[x][y] = map(noise(xoff, yoff), 0, 1, -100, 100);
xoff += 0.2;
}
yoff += 0.2;
}
translate(width / 2, height / 2);
rotateX(PI / 3);
translate(-width, -height / 2 + 50);
for (let y = 0; y < rows - 1; y++) {
beginShape(TRIANGLE_STRIP);
for (let x = 0; x < cols; x++) {
vertex(x * scl, y * scl, terrain[x][y]);
vertex(x * scl, (y + 1) * scl, terrain[x][y + 1]);
// rect(x * scl, y * scl, scl, scl);
}
endShape();
}
}
function create2DArray(numArrays, numSubArrays) {
var arr = new Array(numArrays);
for (var i = 0; i < numArrays; i++) {
arr[i] = new Array(numSubArrays);
}
return arr;
}