-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathColorSchemeDesigner.py
More file actions
159 lines (125 loc) · 5.32 KB
/
Copy pathColorSchemeDesigner.py
File metadata and controls
159 lines (125 loc) · 5.32 KB
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import os
import random
from PIL import Image
from conversion import HSVtoRGB, RGBtoHSV, RGBtoHEX
def create_scheme(color):
"""Create a color scheme with 5 colors and save them as a file."""
schemes = [create_compl_scheme, create_mono_scheme, create_split_scheme,
create_triadic_scheme, create_tetradic_scheme, create_analogous_scheme]
colors = random.choice(schemes)(color)
color_array = [RGBtoHEX(c) for c in colors]
print(color_array)
img = Image.new('RGB', (500, 100), colors[0])
img.paste(colors[1], [100, 0, 200, 100])
img.paste(colors[2], [200, 0, 300, 100])
img.paste(colors[3], [300, 0, 400, 100])
img.paste(colors[4], [400, 0, 500, 100])
img.save(f"{os.getcwd()}/{'_'.join(color_array)}.png")
def create_compl_scheme(color):
"""Create a color scheme with complementary colors."""
colors = [tuple(color)]
colors.append(tuple(change_saturation(color, random.random())))
colors.append(tuple(complementary(color)))
colors.append(tuple(change_saturation(colors[2], random.random())))
colors.append(tuple(change_brightness(change_saturation(
colors[2], random.random()), random.random())))
return colors
def create_mono_scheme(color):
"""Create a 'monotone' color scheme. Not completely monotone to
make it more exciting. Instead, the color will slowly shift in each color.
Starting brightness at one point, will shift further down. Since brightness
becomes less with each step it should start with at least 58% to not end
too dark but start with not more than 98% to not be pure white."""
brightness = random.uniform(0.588, 0.98)
colors = [tuple(change_brightness(color, brightness))]
for x in range(0, 4):
brightness -= 0.098
colors.append(tuple(change_brightness(
change_hue(colors[0], 9), brightness)))
return colors
def create_split_scheme(color):
"""Create a color scheme with split complementary colors."""
colors = [tuple(color)]
colors.append(tuple(change_brightness(change_saturation(
color, random.random()), random.random())))
colors.append(
tuple(change_hue(change_saturation(color, random.random()), 150)))
colors.append(tuple(change_hue(color, -210)))
colors.append(tuple(change_brightness(change_saturation(
colors[3], random.random()), random.random())))
return colors
def create_triadic_scheme(color):
"""Create a color scheme with triadic colors."""
colors = [tuple(color)]
colors.append(tuple(change_brightness(change_saturation(
color, random.random()), random.random())))
colors.append(
tuple(change_hue(change_saturation(color, random.random()), 120)))
colors.append(tuple(change_hue(color, 240)))
colors.append(tuple(change_brightness(change_saturation(
colors[-1], random.random()), random.random())))
return colors
def create_tetradic_scheme(color):
"""Create a color scheme with tetradic colors."""
colors = [tuple(color)]
colors.append(tuple(change_brightness(change_saturation(
color, random.random()), random.random())))
colors.append(
tuple(change_hue(change_saturation(color, random.random()), 90)))
colors.append(tuple(change_hue(color, 180)))
colors.append(tuple(change_brightness(change_saturation(
change_hue(color, 270), random.random()), random.random())))
return(colors)
def create_analogous_scheme(color):
"""Create a color scheme with analogous colors."""
colors = [tuple(color)]
colors.append(tuple(change_brightness(change_saturation(
color, random.random()), random.random())))
colors.append(
tuple(change_hue(change_saturation(color, random.random()), 30)))
colors.append(tuple(change_hue(color, 60)))
colors.append(tuple(change_brightness(change_saturation(
change_hue(color, 90), random.random()), random.random())))
return colors
def random_color():
"""Create a random color in list format."""
return(random.sample(range(255), 3))
def complementary(color):
"""Give the complementary color given one color saved as string."""
try:
if not valid_color(color):
raise ValueError("Given color is not valid!")
except (TypeError, ValueError) as e:
print(e)
print(color)
exit()
else:
return [abs(n - 255) for n in color]
def change_saturation(color, percentage):
"""Changes the saturation of the given color to the given percentage.
Percentage should be float between 0 and 1."""
result = RGBtoHSV(color)
result[1] = percentage
return(HSVtoRGB(result))
def change_brightness(color, percentage):
"""Changes the brightness of the given color to the given percentage.
Percentage should be between 0 and 100."""
result = RGBtoHSV(color)
result[2] = percentage
return(HSVtoRGB(result))
def change_hue(color, degree):
"""Changes the hue of the given color to the given degree."""
result = RGBtoHSV(color)
result[0] += degree
if result[0] > 360:
result[0] -= 360
elif result[0] < 0:
result[0] += 360
return(HSVtoRGB(result))
def valid_color(color):
"""Checks if given list is a valid color."""
if len(color) == 3:
return all(0 <= n <= 255 for n in color)
return False
if __name__ == '__main__':
create_scheme(random_color())