-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest2.py
175 lines (156 loc) · 4.31 KB
/
test2.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
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import math
from colorsys import rgb_to_hls
from colorsys import hls_to_rgb
def perceived_brightness(r,g,b):
#https://alienryderflex.com/hsp.html
#rgb = hex_to_rgb(value)
return math.sqrt( (0.299 * r * r) + (0.587 * g * g) + (0.114 * b * b) )
def pb_r(g, b, pb):
try:
return math.sqrt( ( (pb*pb) - (0.587 * g * g) - (0.114 * b * b) ) / 0.299 )
except:
return -1
def pb_g(r, b, pb):
try:
return math.sqrt( ( (pb*pb) - (0.299 * r * r) - (0.114 * b * b) ) / 0.587 )
except:
return -1
def pb_b(r, g, pb):
try:
return math.sqrt( ( (pb*pb) - (0.299 * r * r) - (0.587 * g * g) ) / 0.114 )
except:
return -1
def rgb_to_hex(value):
return '#%02x%02x%02x' % (int(value[0]*255.0), int(value[1]*255.0), int(value[2]*255.0))
def hex_to_rgb(value):
h = value.lstrip('#')
if len(h) == 6:
return tuple(int(h[i:i+2], 16)/255.0 for i in (0, 2, 4))
else:
return tuple(int(h[i], 16)/15.0 for i in (0, 1, 2))
def find_r(pb):
for g in range(0,255):
for b in range(0,255):
r = pb_r(g/255, b/255, pb)
if r > 0 and r < 1:
hls = rgb_to_hls(r,g/255,b/255)
hue = hls[0]
light = hls[1]
sat = hls[2]
if light == 0.5 and (abs(sat-0.47) < 0.01 or abs(sat-0.57) < 0.01 or abs(sat-0.67) < 0.01 or abs(sat-0.77) < 0.01 or abs(sat-0.87) < 0.01):
rgb = rgb_to_hex(hls_to_rgb(hue,light,sat))
colors.add(rgb)
def find_g(pb):
for r in range(0,255):
for b in range(0,255):
g = pb_g(r/255, b/255, pb)
if g > 0 and g < 1:
hls = rgb_to_hls(r/255,g,b/255)
hue = hls[0]
light = hls[1]
sat = hls[2]
if light == 0.5 and (abs(sat-0.47) < 0.01 or abs(sat-0.57) < 0.01 or abs(sat-0.67) < 0.01 or abs(sat-0.77) < 0.01 or abs(sat-0.87) < 0.01):
rgb = rgb_to_hex(hls_to_rgb(hue,light,sat))
colors.add(rgb)
def find_b(pb):
for r in range(0,255):
for g in range(0,255):
b = pb_b(r/255, g/255, pb)
if b > 0 and b < 1:
hls = rgb_to_hls(r/255,g/255,b)
hue = hls[0]
light = hls[1]
sat = hls[2]
if light == 0.5 and (abs(sat-0.47) < 0.01 or abs(sat-0.57) < 0.01 or abs(sat-0.67) < 0.01 or abs(sat-0.77) < 0.01 or abs(sat-0.87) < 0.01):
rgb = rgb_to_hex(hls_to_rgb(hue,light,sat))
colors.add(rgb)
colors = set()
find_r(0.41)
find_r(0.42)
find_r(0.43)
find_r(0.44)
find_r(0.45)
find_r(0.46)
find_r(0.47)
find_r(0.48)
find_r(0.49)
find_r(0.5)
find_r(0.51)
find_r(0.52)
find_r(0.53)
find_r(0.54)
find_r(0.55)
find_r(0.56)
find_r(0.57)
find_r(0.58)
find_r(0.59)
find_g(0.41)
find_g(0.42)
find_g(0.43)
find_g(0.44)
find_g(0.45)
find_g(0.46)
find_g(0.47)
find_g(0.48)
find_g(0.49)
find_g(0.5)
find_g(0.51)
find_g(0.52)
find_g(0.53)
find_g(0.54)
find_g(0.55)
find_g(0.56)
find_g(0.57)
find_g(0.58)
find_g(0.59)
find_b(0.41)
find_b(0.42)
find_b(0.43)
find_b(0.44)
find_b(0.45)
find_b(0.46)
find_b(0.47)
find_b(0.48)
find_b(0.49)
find_b(0.5)
find_b(0.51)
find_b(0.52)
find_b(0.53)
find_b(0.54)
find_b(0.55)
find_b(0.56)
find_b(0.57)
find_b(0.58)
find_b(0.59)
scolors = {}
for color in sorted(colors):
rgb = hex_to_rgb(color)
hls = rgb_to_hls(rgb[0],rgb[1],rgb[2])
scolors[color] = round(hls[0]*50,0) + hls[2]
head="""
<!DOCTYPE html>
<html>
<title>colors</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<body>
<div class="w3-row-padding" style="color:#fff">
"""
print(head)
cnt = 2
for color in sorted(scolors, key=scolors.get):
if cnt == 0:
print('<div class="w3-center w3-padding w3-col l1 m2 s3" style="background-color:'+color+';cursor: copy;" onclick="copyColor(this.textContent);">'+color+'</div>')
cnt = 2
else:
cnt -= 1
foot="""
</div>
<script>
function copyColor(color) {
navigator.clipboard.writeText(color);
}
</script>
</body>
</html>"""
print(foot)