-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTerrain.txt
84 lines (58 loc) · 1.61 KB
/
Terrain.txt
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
78
79
80
81
82
83
84
package asd;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import javax.imageio.ImageIO;
public class Main {
public static void main(String[] args) {
BufferedImage image = null;
try {
image = ImageIO.read(new File("D:/Downloads/heightmap.png"));
} catch (IOException e) {
e.printStackTrace();
}
float MAX_PIXEL_COLOR = 256 * 256 * 256;
float MAX_HEIGHT = 80;
float[][] tmp = new float[image.getHeight()][image.getWidth()];
for (int i = 0; i < image.getHeight(); i++) {
for (int j = 0; j < image.getWidth(); j++) {
if(j < 0 || j >= image.getHeight() || i < 0 || i >= image.getHeight()) {
tmp[i][j] = 0f;
continue;
}
float height = (float)image.getRGB(i, j);
height += MAX_PIXEL_COLOR / 2.0f;
height /= MAX_PIXEL_COLOR / 2.0f;
height *= MAX_HEIGHT;
if(height > 10) {
//System.out.println(height);
}
// heights.add(height);
tmp[i][j] = height;
}
}
try {
FileWriter fw = new FileWriter(new File("heightMap.txt"));
for (int x = 0; x < image.getHeight(); x++) {
for (int y = 0; y < image.getWidth(); y++) {
if(y < image.getWidth() - 1) {
fw.write(Float.toString(tmp[x][y]) + ",");
}
if(y == image.getWidth() - 1) {
fw.write(Float.toString(tmp[x][y]));
}
}
if(x == image.getHeight() - 1) {
break;
}
fw.write("\n");
}
fw.close();
} catch (IOException e) {
e.printStackTrace();
}
float[][] h = new float[128][128];
System.out.println(h.length);
}
}