๐Ÿ› ๏ธToolsShed

Color Scheme Generator

Generate harmonious color schemes using color theory.

Color Palette

#4F46E5
#DDE548

์ž์ฃผ ๋ฌป๋Š” ์งˆ๋ฌธ

์ฝ”๋“œ ๊ตฌํ˜„

import colorsys

def hex_to_hsl(hex_color: str):
    hex_color = hex_color.lstrip('#')
    r, g, b = (int(hex_color[i:i+2], 16) / 255 for i in (0, 2, 4))
    h, l, s = colorsys.rgb_to_hls(r, g, b)
    return h * 360, s * 100, l * 100

def hsl_to_hex(h: float, s: float, l: float) -> str:
    r, g, b = colorsys.hls_to_rgb(h / 360, l / 100, s / 100)
    return '#{:02x}{:02x}{:02x}'.format(int(r*255), int(g*255), int(b*255))

def generate_scheme(hex_color: str, scheme_type: str):
    h, s, l = hex_to_hsl(hex_color)
    if scheme_type == 'complementary':
        return [hex_color, hsl_to_hex((h + 180) % 360, s, l)]
    elif scheme_type == 'triadic':
        return [hsl_to_hex((h + i * 120) % 360, s, l) for i in range(3)]
    elif scheme_type == 'analogous':
        return [hsl_to_hex((h + i * 30) % 360, s, l) for i in (-1, 0, 1)]
    elif scheme_type == 'monochromatic':
        return [hsl_to_hex(h, s, l + i * 15) for i in range(-2, 3)]
    return [hex_color]

# Example usage
colors = generate_scheme('#3b82f6', 'triadic')
print('Triadic scheme:', colors)

Comments & Feedback

Comments are powered by Giscus. Sign in with GitHub to leave a comment.