Created
July 3, 2015 09:57
-
-
Save jonaslsaa/3afdb8d7b1a44b06a965 to your computer and use it in GitHub Desktop.
Random Terrain Generation in Java (Processing)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int windowX = 800; //Default 800 X 600 | |
int windowY = 600; | |
int[] terrain = new int[windowX]; | |
int count = 2; | |
int start; | |
int temp_z; | |
void setup(){ | |
background(0,0,0); | |
frameRate(10000); | |
size(windowX,windowY); | |
noStroke(); | |
start = (int)random(0,windowX); | |
terrain[1] = (int)random(0,windowX); | |
println(terrain); | |
} | |
void draw(){ | |
background(0,0,0); | |
fill(255,0,0); | |
// Draws Stack | |
for (int j = 0; j < terrain.length; j++){ | |
rect(j,terrain[j],1,windowY); | |
} | |
if (count < windowX){ | |
temp_z = (int)random(0,100); | |
if (temp_z < random(45,55)){ | |
terrain[count] = terrain[count-1]+(int)random(1,2); | |
} else { | |
terrain[count] = terrain[count-1]-(int)random(1,2); | |
} | |
count++; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment