-
Notifications
You must be signed in to change notification settings - Fork 0
/
render_map.py
79 lines (76 loc) · 4.18 KB
/
render_map.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
from common_functions import *
from defines import *
from PIL import Image
import random
owner_colors = {"---": (100, 100, 100), "none": (100, 100, 100)}
religion_colors = {}
culture_colors = {}
previous_days = 0
out_map = Image.new("RGB", (PROVINCE_MAP_WIDTH, PROVINCE_MAP_HEIGHT))
def render_to_date(date, province_mapping, provinces, colonial_colors, mode="owner"):
global previous_days, out_map
days = date_to_days(date)
for province in provinces:
if province.id in province_mapping.keys():
changed = has_changed(previous_days, days, province, mode)
new_color = changed
if province.type == "sea":
if previous_days != 0:
new_color = False
else:
new_color = True
color = C_OCEAN
elif province.type == "wasteland":
if previous_days != 0:
new_color = False
else:
new_color = True
color = C_WASTELAND
elif changed:
if mode == "owner" or mode == "combined":
current_owner = contemporary_event(date, province.owner)[1]
if current_owner not in owner_colors.keys():
if current_owner in colonial_colors.keys():
owner_colors[current_owner] = colonial_colors[current_owner]
else:
owner_colors[current_owner] = get_country_color(get_full_country_name(current_owner))
color = owner_colors[current_owner]
elif mode == "controller":
current_owner = contemporary_event(date, province.controller)[1]
if current_owner not in owner_colors.keys():
if current_owner in colonial_colors.keys():
owner_colors[current_owner] = colonial_colors[current_owner]
else:
owner_colors[current_owner] = get_country_color(get_full_country_name(current_owner))
color = owner_colors[current_owner]
elif mode == "religion":
current_owner = contemporary_event(date, province.religion)[1]
if current_owner not in religion_colors.keys():
religion_colors[current_owner] = (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
color = religion_colors[current_owner]
elif mode == "culture":
current_owner = contemporary_event(date, province.culture)[1]
if current_owner not in culture_colors.keys():
culture_colors[current_owner] = (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
color = culture_colors[current_owner]
if mode == "combined":
current_owner = contemporary_event(date, province.controller)[1]
if current_owner not in owner_colors.keys():
if current_owner in colonial_colors.keys():
owner_colors[current_owner] = colonial_colors[current_owner]
else:
owner_colors[current_owner] = get_country_color(get_full_country_name(current_owner))
secondary_color = owner_colors[current_owner]
if new_color:
pixels = province_mapping[province.id]
for pixel in pixels:
if mode == "combined" and province.type != "sea" and province.type != "wasteland":
pixel_distance = pixel[0] * 2 ** 0.5 - pixel[1] * 2 ** 0.5
if abs(pixel_distance) % HASHED_LINE_SPACING < 1.45:
out_map.putpixel(pixel, secondary_color)
else:
out_map.putpixel(pixel, color)
else:
out_map.putpixel(pixel, color)
previous_days = days
return out_map