forked from MrCheeze/botw-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
heightmap_water.py
55 lines (51 loc) · 1.74 KB
/
heightmap_water.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
43
44
45
46
47
48
49
50
51
52
53
54
55
from PIL import Image, ImageDraw, ImageFilter
import os
import math
img = Image.new("HSV", (0x40*6*2, 0x40*6*2))
i = 0
for folder, _, files in os.walk('terrain_water'):
if folder == 'terrain_water':
continue
y_high = [0,0,0,1,2,1,
1,2,2,0,0,0,
1,1,2,2,1,2,
3,4,3,3,4,4,
5,5,5,3,3,4,
4,3,4,5,5,5][i] * 0x80
x_high = [0,1,2,0,0,1,
2,1,2,3,4,5,
3,4,3,4,5,5,
0,0,1,2,1,2,
0,1,2,3,4,3,
4,5,5,3,4,5][i] * 0x80
for file in files:
if file == '.gitignore':
continue
tile = int(file[-13:-11],0x10)%4
if tile == 0:
x_mid = 0
y_mid = 0
elif tile == 1:
x_mid = 0x40
y_mid = 0
elif tile == 2:
x_mid = 0
y_mid = 0x40
elif tile == 3:
x_mid = 0x40
y_mid = 0x40
print(file)
f = open(folder+'/'+file, 'rb')
for y in range(y_high + y_mid, y_high + y_mid + 0x40):
for x in range(x_high + x_mid, x_high + x_mid + 0x40):
height = int.from_bytes(f.read(2),'little') // 256
x_flow = int.from_bytes(f.read(2),'little') - 0x8000
y_flow = int.from_bytes(f.read(2),'little') - 0x8000
f.read(1)
material = int.from_bytes(f.read(1),'little') * 32
angle = int(math.atan2(y_flow, x_flow) * 128/math.pi + 128)
magnitude = int(23*math.log(1+math.hypot(x_flow, y_flow)))
img.putpixel((x,y), (height, 255, 255))
f.close()
i += 1
img.convert("RGB").filter(ImageFilter.FIND_EDGES).save('heightmap_water.png')