Skip to content

Commit ce6c3ff

Browse files
committed
Hued version 1.0.6.
1 parent bf91d6d commit ce6c3ff

File tree

7 files changed

+255
-130
lines changed

7 files changed

+255
-130
lines changed

Tests/test_palettes.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
from hued.palettes import ColorPalette
23

34
def test_generate_complementary():
@@ -119,6 +120,74 @@ def test_generate_random_hex_colors():
119120
assert isinstance(result, list), "Expected a list for the random HEX colors."
120121
print("Random HEX Colors:", result)
121122

123+
def test_generate_gradient():
124+
print("Testing Gradient Generation...")
125+
base_color = (255, 60, 52) # Example base color (Red)
126+
palette = ColorPalette(base_color)
127+
start_color = (255, 60, 52) # Start color (Red)
128+
end_color = (51, 247, 255) # End color (Cyan)
129+
expected_gradient = [
130+
(255, 60, 52),
131+
(214, 97, 92),
132+
(173, 134, 133),
133+
(132, 172, 173),
134+
(91, 209, 214),
135+
(51, 247, 255)
136+
]
137+
result = palette.generate_gradient(start_color, end_color, steps=5)
138+
assert result == expected_gradient, f"Expected {expected_gradient}, but got {result}"
139+
print(f"Gradient: {result}")
140+
141+
def test_export_palette():
142+
print("Testing Palette Export...")
143+
base = (255, 60, 52) # Red
144+
cp = ColorPalette(base)
145+
146+
# 1. Export a simple list palette (e.g., complementary)
147+
print("Generating Complementary...")
148+
comp_palette = cp.generate_complementary() # self.palette is now the complementary list
149+
print(f"Current Palette (Complementary List): {cp.palette}")
150+
try:
151+
cp.export_palette("complementary_palette.json")
152+
cp.export_palette("complementary_palette.txt")
153+
cp.export_palette("complementary_palette.csv")
154+
print("Exported complementary list palette.")
155+
except Exception as e:
156+
print(f"Error exporting complementary: {e}")
157+
158+
159+
# 2. Generate and export a complex dictionary palette
160+
print("\nGenerating Random Palette Dictionary...")
161+
# Generate the dict and set it as the current palette
162+
random_palette_dict = cp.generate_random_palette()
163+
print(f"Current Palette (Random Dict): Keys = {cp.palette.keys()}")
164+
try:
165+
cp.export_palette("random_palette_structure.json")
166+
cp.export_palette("random_palette_structure.txt")
167+
cp.export_palette("random_palette_structure.csv")
168+
print("Exported random dictionary palette.")
169+
except Exception as e:
170+
print(f"Error exporting random dict: {e}")
171+
172+
# 3. Generate a gradient (doesn't modify self.palette) and export it separately
173+
print("\nGenerating Gradient...")
174+
gradient = cp.generate_gradient((255, 0, 0), (0, 0, 255), steps=5)
175+
# To export the gradient, temporarily set it as the palette
176+
original_palette = cp.palette # Save current palette
177+
cp.palette = gradient
178+
print(f"Current Palette (Gradient List): {cp.palette}")
179+
try:
180+
cp.export_palette("gradient_palette.json")
181+
cp.export_palette("gradient_palette.txt")
182+
cp.export_palette("gradient_palette.csv")
183+
print("Exported gradient list palette.")
184+
except Exception as e:
185+
print(f"Error exporting gradient: {e}")
186+
finally:
187+
cp.palette = original_palette # Restore previous palette
188+
189+
print("\Exporting complete.")
190+
122191
def run_tests():
123192
test_generate_complementary()
124193
test_generate_analogous()
@@ -131,6 +200,8 @@ def run_tests():
131200
test_generate_random_palette()
132201
test_generate_random_color()
133202
test_generate_random_hex_colors()
203+
test_generate_gradient()
204+
test_export_palette()
134205
print("All tests passed!")
135206

136207
if __name__ == "__main__":

hued/analysis.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,3 @@
1-
"""
2-
Module: analysis.py
3-
4-
This module provides functions to analyze the properties of colors.
5-
It includes methods to determine the temperature, neutrality, brightness,
6-
and whether a color is pastel, muted, or vibrant.
7-
8-
Functions:
9-
- get_temperature: Determines the temperature of a color based on its RGB values.
10-
- is_neutral: Checks if a color is neutral.
11-
- brightness: Calculates the brightness of a color.
12-
- is_pastel: Checks if a color is pastel.
13-
- is_muted: Checks if a color is muted.
14-
- is_vibrant: Checks if a color is vibrant.
15-
- rgb_to_linear: Convert RGB values to linear RGB.
16-
- get_luminance: Calculate the relative luminance of an RGB color.
17-
- get_vibrancy: Calculate the vibrancy of an RGB color.
18-
- color_contrast: Calculates the contrast ratio between two colors using their RGB values.
19-
- get_text_color_from_background: Determines whether the text should be "light" or "dark" based on the background color.
20-
"""
21-
221
from hued.conversions import rgb_to_hsv
232

243
def get_temperature(rgb):

hued/colors.py

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,3 @@
1-
"""
2-
Module: colors.py
3-
4-
This module provides functionality for working with a predefined list of named colors.
5-
It includes methods to search for the closest color name given a hex value and to retrieve
6-
color information such as RGB and HEX values.
7-
8-
Classes:
9-
- ColorManager: Manages predefined color data and provides search functionality.
10-
11-
Methods:
12-
- ColorManager.__init__: Initializes the color manager with a predefined list of colors.
13-
- ColorManager.hex_to_rgb: Converts a hex color code to RGB.
14-
- ColorManager.rgb_to_hex: Converts RGB values to a hex color code.
15-
- ColorManager.closest_color_name: Finds the closest color name given a hex value.
16-
- ColorManager.get_color_by_name: Returns the hex and RGB values of a color based on its name.
17-
"""
18-
19-
201
class ColorManager:
212
"""
223
Manages a collection of predefined named colors and provides methods for color search
@@ -1415,4 +1396,4 @@ def get_color_by_name(self, name):
14151396
'Hex': hex_value,
14161397
'RGB': rgb_value
14171398
}
1418-
return None
1399+
return None

hued/conversions.py

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,3 @@
1-
"""
2-
Module: conversions.py
3-
4-
This module provides methods for converting between different color formats,
5-
including RGB, HEX, HSL, HSV, and CMYK.
6-
7-
Methods:
8-
- rgb_to_hex(r, g, b): Converts RGB to HEX.
9-
- rgb_to_hsl(r, g, b): Converts RGB to HSL.
10-
- rgb_to_hsv(r, g, b): Converts RGB to HSV.
11-
- rgb_to_cmyk(r, g, b): Converts RGB to CMYK.
12-
- rgb_to_xyz(r, g, b): Converts RGB to XYZ.
13-
- hex_to_rgb(hex_value): Converts HEX to RGB.
14-
- hex_to_hsl(hex_value): Converts HEX to HSL.
15-
- hex_to_hsv(hex_value): Converts HEX to HSV.
16-
- hex_to_cmyk(hex_value): Converts HEX to CMYK.
17-
- hex_to_xyz(hex_value): Converts HEX to XYZ.
18-
- hsl_to_rgb(h, s, l): Converts HSL to RGB.
19-
- hsl_to_hex(hsl_value): Converts HSL to HEX.
20-
- hsl_to_hsv(hsl_value): Converts HSL to HSV.
21-
- hsl_to_cmyk(hsl_value): Converts HSL to CMYK.
22-
- hsl_to_xyz(hsl_value): Converts HSL to XYZ.
23-
- hsv_to_rgb(h, s, v): Converts HSV to RGB.
24-
- hsv_to_hex(hsv_value): Converts HSV to HEX.
25-
- hsv_to_hsl(hsv_value): Converts HSV to HSL.
26-
- hsv_to_cmyk(hsv_value): Converts HSV to CMYK.
27-
- hsv_to_xyz(hsv_value): Converts HSV to XYZ.
28-
- cmyk_to_rgb(c, m, y, k): Converts CMYK to RGB.
29-
- cmyk_to_hex(cmyk_value): Converts CMYK to HEX.
30-
- cmyk_to_hsl(cmyk_value): Converts CMYK to HSL.
31-
- cmyk_to_hsv(cmyk_value): Converts CMYK to HSV.
32-
- cmyk_to_xyz(cmyk_value): Converts CMYK to XYZ.
33-
- xyz_to_rgb(x, y, z): Converts XYZ to RGB.
34-
- xyz_to_hex(xyz_value): Converts XYZ to HEX.
35-
- xyz_to_hsl(xyz_value): Converts XYZ to HSL.
36-
- xyz_to_hsv(xyz_value): Converts XYZ to HSV.
37-
- xyz_to_cmyk(xyz_value): Converts XYZ to CMYK.
38-
- blend_colors(color1, color2, ratio=0.5): Blends two colors in the RGB format (tuple) using the specified ratio.
39-
"""
40-
411
def rgb_to_hex(r, g, b):
422
"""
433
Converts RGB values to a hex color code.

0 commit comments

Comments
 (0)