-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNoiseMap.pde
77 lines (67 loc) · 1.84 KB
/
NoiseMap.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
72
73
74
75
76
77
class NoiseMap {
float[][] NoiseField;
int cols, rows, octaves, seed, heightScale;
float scale, persistance, lacunarity;
NoiseMap(int c, int r) {
this(c, r, 0.02);
}
NoiseMap(int c, int r, float s) {
this(c, r, 1, s, int(random(500, 5000)));
}
NoiseMap(int c, int r, int hs, float s) {
this(c, r, hs, s, int(random(500, 5000)));
}
NoiseMap(int c, int r, int hs, float s, int _seed) {
this(c, r, hs, s, _seed, 1, .5, 2);
}
NoiseMap(int c, int r, int hs, float s, int _seed, int oct, float pers, float lacu) {
cols = c;
rows = r;
scale = s;
octaves = oct;
persistance = pers;
lacunarity = lacu;
seed = _seed;
heightScale = hs;
NoiseField = new float[cols][rows];
generateMap();
}
void generateMap() {
float yoff = seed;
for (int y = 0; y<rows; y++) {
float xoff = seed;
for (int x = 0; x<cols; x++) {
//float amplitude = 1;
//float frequency = 1;
//float noiseHeight = 0;
for (int o = 0; o<=octaves; o++) {
NoiseField[x][y] = noise(xoff, yoff);
//xoff = x/scale * frequency;
//yoff = y/scale * frequency;
//noiseHeight += terrain[x][y] * amplitude;
//amplitude *= persistance;
//frequency *= lacunarity;
}
xoff += scale;
}
yoff += scale;
}
}
void display2D(color c1, color c2) {
int xwid = width/cols;
int ywid = height/rows;
for (int y = 0; y<rows; y++) {
for (int x = 0; x<cols; x++) {
//fill(color(map(this.getValue(x, y), 0, this.heightScale, 0, 255)));
fill(lerpColor(c1,c2,this.getValue(x, y)/this.heightScale));
rect(x*xwid, y*ywid, x+xwid, y+ywid);
}
}
}
void display2D() {
display2D(0,255);
}
float getValue(int x, int y) {
return NoiseField[x][y]*heightScale;
}
}