-
Notifications
You must be signed in to change notification settings - Fork 0
/
cartographer.py
145 lines (107 loc) · 4.12 KB
/
cartographer.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
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
from concurrent.futures import ProcessPoolExecutor
from PIL import Image
from utils import resize
import seaborn as sb
import numpy as np
import matplotlib.pyplot as plt
from time import time
Image.MAX_IMAGE_PIXELS = None
# noinspection SpellCheckingInspection
def sb_heatmap(arr, cmap, path):
start_time = time()
# cmap reference: https://matplotlib.org/stable/gallery/color/colormap_reference.html
sb.heatmap(arr, square=True, cbar=False, xticklabels=False,
yticklabels=False, cmap=cmap)
plt.tight_layout()
plt.savefig(path, dpi=2048, transparent=True, format="png", bbox_inches="tight", pad_inches=0)
# Convert to RGBA for Ursina.
print(f"{path} created in {round(time() - start_time, 2)}s")
return path
def create_surface_texture(save, slopes):
print(f"creating surface texture")
start = time()
max_value_index = np.unravel_index(slopes.argmax(), slopes.shape)
max_value = slopes[max_value_index[0]][max_value_index[1]]
colors = np.full(slopes.shape, 255.0)
for i in range(int(max_value)):
random_array = np.random.uniform(low=2, high=5, size=slopes.shape)
slopes -= 1
non_zero_mask = slopes > 0
colors = np.where(non_zero_mask, colors - random_array, colors)
colors[colors < 0] = 0
# Multiplying by 3 gives us (color, color, color) [Not exactly but it kind of represents the RGB values]
image_array = np.stack([colors] * 3, axis=-1)
texture = Image.fromarray(np.uint8(image_array), mode="RGB")
print(f"{save.moon_surface_texture_image} created in {round(time() - start, 2)}s")
texture.save(save.moon_surface_texture_image)
# noinspection SpellCheckingInspection
# Creates RAW_Heightmap, Slopemap, and Heightkey with Threading
def draw_maps(save):
parsed_arr = np.load(save.data_file)
heights = parsed_arr[:, :, 8]
slopes = parsed_arr[:, :, 3]
with ProcessPoolExecutor() as exc:
raw_heightmap_future = exc.submit(sb_heatmap, heights, "gist_gray", save.raw_heightmap_image)
heightkey_future = exc.submit(sb_heatmap, heights, "viridis", save.heightkey_surface_image)
slopemap_future = exc.submit(sb_heatmap, slopes, "inferno", save.slopemap_image)
texture_future = exc.submit(create_surface_texture, save, slopes)
raw_heightmap = raw_heightmap_future.result()
heightkey = heightkey_future.result()
slopemap = slopemap_future.result()
texture = texture_future.result()
return raw_heightmap, heightkey, slopemap, slopemap, texture
# noinspection PyUnusedLocal
def create_images(save):
print("creating all images")
start = time()
# Create the essential images.
draw_maps(save)
# Image Scaling for Faster Ursina Runs, as well as proper dimensions.
proper_heightmap = resize(
image_path=save.raw_heightmap_image,
path=save.processed_heightmap,
scale=128,
transpose=True
)
proper_surface_texture = resize(
image_path=save.moon_surface_texture_image,
path=save.moon_surface_texture_image,
scale=save.size,
transpose=True
)
flipped_slopemap = resize(
image_path=save.slopemap_image,
path=save.slopemap_image,
scale=save.size,
transpose=True
)
flipped_heightmap = resize(
image_path=save.heightkey_surface_image,
path=save.heightkey_surface_image,
scale=save.size,
transpose=True
)
minimap = resize(
image_path=save.moon_surface_texture_image,
path=save.minimap_image,
scale=128
)
interface_slopemap = resize(
image_path=save.slopemap_image,
path=save.interface_slopemap_image,
scale=500
)
interface_texture = resize(
image_path=save.moon_surface_texture_image,
path=save.interface_texture_image,
scale=500
)
interface_heightkey = resize(
image_path=save.heightkey_surface_image,
path=save.interface_heightkey_image,
scale=500
)
print(f"cartographer created images in {round(time() - start, 2)}s")
if __name__ == "__main__":
# create_images()
pass