Skip to content

Instantly share code, notes, and snippets.

@Andrew-Pynch
Created August 17, 2020 17:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Andrew-Pynch/ba306a585465375340bb3b52c51a3027 to your computer and use it in GitHub Desktop.
Save Andrew-Pynch/ba306a585465375340bb3b52c51a3027 to your computer and use it in GitHub Desktop.
int rows, cols;
int scl = 20;
int w = 2920;
int h = 1080;
float flying = 0;
// 2d array in java
float[][] terrain;
void setup() {
size(600, 600, P3D);
cols = w / scl;
rows = h / scl;
terrain = new float[cols][rows];
}
void draw() {
background(0);
stroke(255);
noFill();
flying -= 0.1;
float yoff = flying;
for (int y = 0; y < rows; y++) {
float xoff = 0;
for (int x = 0; x < cols; x++) {
terrain[x][y] = map(noise(xoff, yoff), 0, 1, -100, 100);
xoff += 0.2;
}
yoff += 0.2;
}
// Translate relative to center
translate(width/2, height/2+50);
rotateX(PI/3);
translate(-w/2, -h/2);
for (int y = 0; y < rows-1; y++) {
beginShape(TRIANGLE_STRIP);
for (int 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();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment