Skip to content

Commit 54c5208

Browse files
author
Lucy Ivatt
committed
Added Hex codes under colour swatches
1 parent ea331b9 commit 54c5208

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

colourSchemeDetector.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
import os
99

1010
TEST_PATH = "Auto-Colour-Scheme-Generator//pexels-photo.jpeg"
11+
DARK_GREY = (33, 37, 43)
12+
LIGHT_GREY = (41, 45, 53)
1113

1214
def rgb_to_hex(colour):
13-
hex_values = [hex(int(value.item())) for value in colour]
15+
hex_values = [hex(int(value)) for value in colour]
1416
final_string = "#"
1517
for value in hex_values:
1618
sub_string = str(value).lstrip("0x")
@@ -45,7 +47,6 @@ def get_colours(image):
4547

4648
# Get ordered colours by iterating through keys
4749
ordered_colours = [center_colours[i] for i in counts.keys()]
48-
hex_colours = [rgb_to_hex(ordered_colours[i]) for i in counts.keys()]
4950
rgb_colours = [tuple(ordered_colours[i].tolist()) for i in counts.keys()]
5051

5152
return rgb_colours
@@ -55,10 +56,19 @@ def draw_swatches(rgb_colours):
5556
pygame.init()
5657
pygame.font.init()
5758
font = pygame.font.SysFont('Helvetica', 20)
58-
screen = pygame.display.set_mode((150 * colour_number, 100))
59+
screen = pygame.display.set_mode((150 * colour_number, 130))
5960
x_rectangle_coord = 0
61+
alternate = 1
6062
for i in range(colour_number):
63+
alternate *= -1
64+
if alternate == 1:
65+
title = DARK_GREY
66+
else:
67+
title = LIGHT_GREY
6168
pygame.draw.rect(screen, x[i], (x_rectangle_coord,0, 150, 100))
69+
pygame.draw.rect(screen, title, (x_rectangle_coord,100, 150, 30))
70+
hexcode = font.render(rgb_to_hex(rgb_colours[i]), False, (240, 240, 240))
71+
screen.blit(hexcode, (x_rectangle_coord + (150 - hexcode.get_width()) // 2, 100 + (30 - hexcode.get_height()) // 2))
6272
x_rectangle_coord += 150
6373
pygame.display.update()
6474
print("Press enter to exit")

0 commit comments

Comments
 (0)