-
-
Notifications
You must be signed in to change notification settings - Fork 34
/
colors.py
123 lines (110 loc) · 4.38 KB
/
colors.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
import colorsys
from enum import Enum
import random
color_range = 255
def darken_color(color_array, factor):
factor = max(0, min(factor, 1))
# Scale down each color channel
return tuple(int(channel * (1 - factor)) for channel in color_array)
def hsv2rgb(h, s, v):
return tuple(int(color * color_range) for color in colorsys.hsv_to_rgb(h, s, v))
def generate_colors(color_num):
Hue = [ ((num + 1.0)/color_num, 1, 1) for num in range(color_num) ]
colors = [ hsv2rgb(*hsv_color) for hsv_color in Hue ]
return colors
def generate_team_colors(num_teams, color_lock=False, color_lock_choices=None):
if color_lock and color_lock_choices != None and num_teams in [2,3,4]:
temp_colors = color_lock_choices[num_teams]
return [Colors[c] for c in temp_colors]
if num_teams == 1:
#only Werewolf, and it's ignored anyway, but let's prevent errors, eh?
return [random.choice(team_color_list)]
if num_teams == 2:
team1 = random.choice(team_color_list)
team2 = random.choice(dual_teams[team1])
return [team1, team2]
elif num_teams == 3:
team1 = random.choice(team_color_list)
team2 = random.choice(tri_teams[team1])
allowed = tri_teams[team1] + tri_teams[team2]
team3_allowed = [x for x in allowed if x in tri_teams[team1] and x in tri_teams[team2]]
if team3_allowed:
team3 = random.choice(team3_allowed)
else:
team3 = Colors.White
return [team1,team2,team3]
elif num_teams == 4:
team_a = random.choice([Colors.Orange,Colors.Yellow])
team_b = random.choice([Colors.Purple,Colors.Pink,Colors.Magenta])
teams = [Colors.Green,Colors.Blue,team_a,team_b]
random.shuffle(teams)
return teams
elif num_teams > 4:
#set colors, we're in FFA territory now
sets_needed = (num_teams//8)+1
teams = ordered_color_list*sets_needed
teams = teams[:num_teams]
return teams
def change_color(color_array, r, g, b):
color_array[0] = r
color_array[1] = g
color_array[2] = b
class Colors(Enum):
#first 8 are team colors
Pink = (255,108,108)
Magenta = (255,0,192)
Orange = (255,64,0)
Yellow = (255,255,0)
Green = (0,255,0)
Turquoise = (0,255,255)
Blue = (0,0,255)
Purple = (96,0,255)
#these are used for various things
White = (255,255,255)
White80 = (200,200,200)
White60 = (150,150,150)
White40 = (100,100,100)
White20 = (50,50,50)
White10 = (10,10,10)
Red = (255,0,0)
Red60 = (150,0,0)
Red80 = (200,0,0)
Green80 = (0,200,0)
Green20 = (0,50,0)
Blue40 = (0,0,100)
LimeGreen = (100,255,0)
Zombie = (50,150,50)
Black = (0,0,0)
#stay fresh
SplatoonGreen = (30,220,0)
SplatoonPink = (255,50,120)
team_color_list = [x for x in Colors][0:8]
ordered_color_list = [Colors.Blue,Colors.Yellow,Colors.Green,Colors.Orange,Colors.Purple,
Colors.Magenta,Colors.Turquoise,Colors.Pink]
#pick one color, then pick among the colors not near the first
dual_teams = {
Colors.Pink : [Colors.Yellow,Colors.Green],
Colors.Magenta : [Colors.Yellow,Colors.Green],
Colors.Orange : [Colors.Green,Colors.Turquoise,Colors.Blue,Colors.Purple],
Colors.Yellow : [Colors.Turquoise,Colors.Blue,Colors.Purple,Colors.Pink,Colors.Magenta],
Colors.Green : [Colors.Purple,Colors.Pink,Colors.Magenta,Colors.Orange],
Colors.Turquoise : [Colors.Purple,Colors.Orange,Colors.Yellow],
Colors.Blue : [Colors.Orange,Colors.Yellow],
Colors.Purple : [Colors.Orange,Colors.Yellow,Colors.Green]
}
#remove pairings from dual_teams that don't have a shared third color
#pick two colors like dual_team, then pick third shared between those two
tri_teams = {
Colors.Pink : [Colors.Yellow,Colors.Turquoise,Colors.Blue],
Colors.Magenta : [Colors.Yellow,Colors.Turquoise,Colors.Blue],
Colors.Orange : [Colors.Green,Colors.Turquoise,Colors.Purple],
Colors.Yellow : [Colors.Turquoise,Colors.Blue,Colors.Purple,Colors.Pink,Colors.Magenta],
Colors.Green : [Colors.Purple,Colors.Orange],
Colors.Turquoise : [Colors.Pink,Colors.Magenta,Colors.Orange,Colors.Yellow],
Colors.Blue : [Colors.Pink,Colors.Magenta,Colors.Yellow],
Colors.Purple : [Colors.Orange,Colors.Yellow,Colors.Green]
}
"""
quad_teams - generated above, here's how
all groups have green and blue, one of orange/yellow, one of pink/magenta/purple
"""