-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworldmap.py
84 lines (66 loc) · 1.95 KB
/
worldmap.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
# ![](./worldmap.png)
# # LEGO World Map in Markley’s Projection
# noreorder
from io import StringIO
import numpy as np
import pandas as pd
import plotly.express as px
# ## Load Data Files
elevation = np.load("data/elevation.npy")
land = np.load("data/land.npy")
# ## The Color Palette of LEGO World Map
color_table = """
R, G, B, name
33, 33, 33, Black
255, 255, 255, White
20, 48, 68, Dark Blue
255, 99, 71, Coral
255, 126, 20, Orange
247, 186, 48, Bright Light Orange
222, 198, 156, Tan
166, 202, 85, Lime
16, 203, 49, Bright Green
66, 192, 251, Medium Azure
0, 138, 128, Dark Turquoise
"""
color_table = pd.read_csv(
StringIO(color_table),
skipinitialspace=True,
index_col="name",
)
colors = list(color_table.index)
pallete = np.array(color_table, dtype=np.uint8)
px.imshow(pallete[np.newaxis], width=800)
# ## The Land Map with Shadow
worldmap = np.full_like(land, colors.index("Dark Turquoise"))
worldmap[land == 1] = colors.index("Dark Blue")
worldmap = np.roll(worldmap, 1, axis=1)
worldmap[land == 1] = colors.index("White")
px.imshow(pallete[worldmap], width=800)
# ## The Full World Map with Ocean Topography
block_counts = [
("Coral", 600),
("Orange", 600),
("Bright Light Orange", 600),
("Tan", 725),
("Lime", 1000),
("Bright Green", 600),
("Medium Azure", 1600),
("Dark Turquoise", 2000),
("Black", 10000), # We may not have enough tiles to cover the ocean.
]
blocks = np.concatenate([np.full(count, colors.index(x)) for x, count in block_counts])
ocean = worldmap == colors.index("Dark Turquoise")
rank_by_depth = np.argsort(elevation[ocean])[::-1].argsort()
worldmap[ocean] = blocks[rank_by_depth]
px.imshow(pallete[worldmap], width=800)
# ## Tiled Maps
tiled_map = np.concatenate(
[
np.roll(worldmap, worldmap.shape[1] // 2, axis=1),
np.rot90(worldmap, 2),
worldmap,
]
)
tiled_map = np.tile(tiled_map, 2)
px.imshow(pallete[tiled_map], width=800)