-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathheightmap.py
42 lines (31 loc) · 1.07 KB
/
heightmap.py
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
from PIL import Image, ImageDraw
from colour import Color
import settings as s
import sys
import topng
def setpixel(x, y, value):
img.putpixel((x, y), value)
def heightmap(hm, scale):
SCALER = scale
width, height = hm.size
img = Image.new('I', (width // SCALER, height // SCALER), color='red')
for y in range(0, height, SCALER):
if y % (height // 100) == 0:
print("hm", y / height * 100)
for x in range(0, width // 2, SCALER):
value = hm.getpixel((x, y))
rightVal = hm.getpixel((x + width // 2, y))
try:
img.putpixel((x // SCALER * 2, y // SCALER), value)
img.putpixel((x // SCALER * 2 + 1, y // SCALER), rightVal)
except IndexError:
pass
return img
if __name__ == '__main__':
directory = sys.argv[1]
Image.MAX_IMAGE_PIXELS = 1061683200
hm = Image.open("heightmap.tif")
image = heightmap(hm, s.SCALE)
image.save(directory + "/hm.tif")
scaledpng = topng.to_png(image)
scaledpng.save(directory + "/hm.png")