-
Notifications
You must be signed in to change notification settings - Fork 0
/
TerraGen.pde
71 lines (55 loc) · 1.4 KB
/
TerraGen.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
public class TerraGen
{
int w;
int h;
int rows, cols;
int scale;
int max_height, max_depth;
int fps;
float flight_offset;
float[][] noise_val;
float flight_speed = 0;
TerraGen(int w, int h, int scale, float flight_offset, int max_height, int max_depth, int fps)
{
this.fps = fps;
this.w = w;
this.h = h;
this.scale = scale;
this.flight_offset = flight_offset;
this.max_height = max_height;
this.max_depth = max_depth;
rows = h/scale;
cols = w/scale;
noise_val = new float[rows][cols];
frameRate(fps);
}
void fly()
{
float y_offset = flight_speed;
for(int y = 0; y < rows; y++) {
float x_offset = 0;
for(int x = 0; x < cols ; x++) {
noise_val[y][x] = map(noise(x_offset,y_offset), 0, 1, max_depth, max_height);
x_offset += 0.1;
}
y_offset -= 0.1;
}
flight_speed += flight_offset;
background(255);
noFill();
stroke(0);
translate(width/2, height/2);
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++) {
//color a = color(random(0, 255), random(0, 255), random(0, 255));
//stroke(a);
vertex(x*scale, y*scale, noise_val[y][x]);
vertex(x*scale, (y + 1)*scale, noise_val[y+1][x]);
}
endShape();
}
}
}