-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMapPixel.py
96 lines (84 loc) · 3.41 KB
/
MapPixel.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
__author__ = 'Ian'
import colorsys
class MapPixel:
"""A single unit of map terrain"""
TUNDRA, BOREAL_FOREST, COLD_DESERT, WOODLAND, TEMPERATE_FOREST, TEMPERATE_RAINFOREST, SUBTROPICAL_DESERT, SAVANNA, TROPICAL_RAINFOREST = range(9)
waterColor = (0.55, 1.0, 0.2)
landColor = (0.17, 1.0, 0.1)
def __init__(self, coordinates, height, sea_level):
self.coordinates = coordinates
self.height = height
self.seaLevel = sea_level
self.rainfall = 0.0
self.temperature = 0.0
self.windDirection = 0
self.biome = self.TUNDRA
self.isWater = True if self.height <= self.seaLevel else False
def calculate_biome(self):
if self.temperature < 0.15:
self.biome = self.TUNDRA
elif self.temperature < 0.58:
if self.rainfall < 0.1:
self.biome = self.COLD_DESERT
elif self.rainfall < 0.2:
self.biome = self.WOODLAND
elif self.temperature < 0.2:
self.biome = self.BOREAL_FOREST
elif self.rainfall < 0.35:
self.biome = self.TEMPERATE_FOREST
else:
self.biome = self.TEMPERATE_RAINFOREST
else:
if self.rainfall < 0.12:
self.biome = self.SUBTROPICAL_DESERT
elif self.rainfall < 0.45:
self.biome = self.SAVANNA
else:
self.biome = self.TROPICAL_RAINFOREST
def get_biome_map_color(self):
if self.isWater:
return 0, 0, 0
elif self.biome == self.TUNDRA:
return 165, 208, 230
elif self.biome == self.BOREAL_FOREST:
return 117, 209, 181
elif self.biome == self.COLD_DESERT:
return 209, 191, 117
elif self.biome == self.WOODLAND:
return 171, 78, 41
elif self.biome == self.TEMPERATE_FOREST:
return 39, 125, 46
elif self.biome == self.TEMPERATE_RAINFOREST:
return 53, 150, 61
elif self.biome == self.SUBTROPICAL_DESERT:
return 191, 158, 57
elif self.biome == self.SAVANNA:
return 149, 196, 55
else:
# TROPICAL RAIN FOREST
return 34, 222, 13
def get_rainfall_map_color(self):
if self.isWater:
return (50, 80, 120)
else:
return (int(255*self.rainfall), int(255*self.rainfall), int(255*self.rainfall))
def get_wind_direction_map_color(self):
if self.isWater:
return (0, 0, 0)
else:
hue = float(self.windDirection) / 360.0
col = colorsys.hsv_to_rgb(hue, 1.0, 0.6)
return (int(col[0] * 255), int(col[1] * 255), int(col[2] * 255))
def get_temperature_map_color(self):
if self.isWater:
return (0, 0, 0)
else:
return (int(255*self.temperature), int(255*self.temperature), int(255*self.temperature))
def get_greyscale_color(self):
return (int(255*self.height), int(255*self.height), int(255*self.height))
def get_rgb_color(self):
if(self.isWater):
col = colorsys.hsv_to_rgb(self.waterColor[0], self.waterColor[1], self.waterColor[2] + self.height)
else:
col = colorsys.hsv_to_rgb(self.landColor[0] + (self.rainfall / 10.0), self.landColor[1], self.landColor[2] + self.height)
return (int(col[0] * 255), int(col[1] * 255), int(col[2] * 255))