Created
April 12, 2024 19:17
-
-
Save UncleCJ/88389e0257db91348bf4541acf7ed04a to your computer and use it in GitHub Desktop.
Script to generate color codes from the color wheel to be used with an... ancestral wheel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Tuple | |
from colorsys import rgb_to_hsv, hsv_to_rgb | |
def hex_to_floats(h: str) -> Tuple[float, float, float]: | |
i = int(h, 16) | |
return tuple( | |
(i // 256 ** position & 255) | |
/ 255 | |
for position in [2, 1, 0]) | |
def floats_to_hex(r: float, g: float, b: float) -> str: | |
return hex(int(r * 256) * 256 ** 2 + int(g * 256) * 256 + int(b * 256)) | |
def deg_to_fract(d: float) -> float: | |
return d / 360 | |
def fract_to_deg(f: float) -> float: | |
return f * 360 % 360 | |
def generate_hues(g: int, offset: int = -30): | |
hues = [] | |
ancestors = 2 ** g | |
for i in range(ancestors): | |
h = i * 360 / ancestors + offset + 360 / (2 * ancestors) | |
hues.append(h) | |
return hues | |
def hue_to_code(h: int, s: float = 0.2, v: float = 0.99) -> str: | |
return floats_to_hex(*hsv_to_rgb(deg_to_fract(h), s, v)) | |
if __name__ == "__main__": | |
hexcodes = { | |
"F": "b3f4c5", # Nu blå, H = 240° | |
"FF": "c3edfa", | |
"FM": "d5eea5", | |
"M": "fedac6", # Nu gul, H = 60° | |
"MF": "fed9d9", | |
"MM": "feeab3" | |
} | |
for k, v in hexcodes.items(): | |
print(f"{k} ({v}) = {rgb_to_hsv(*hex_to_floats(v))}") | |
# print(hex_to_floats("b3f4c5")) | |
print(floats_to_hex(0.5, 0.9999, 0.25)) | |
print(list(hue_to_code(h) for h in generate_hues(1))) | |
print(list(hue_to_code(h) for h in generate_hues(2))) | |
print(list(hue_to_code(h) for h in generate_hues(3))) | |
print(list(hue_to_code(h) for h in generate_hues(4))) | |
print(list(hue_to_code(h) for h in generate_hues(5))) | |
print(list(hue_to_code(h) for h in generate_hues(6))) | |
# M: '0xfdfdca', F: '0xcacafd'] | |
# MM: '0xfdd7ca', MF: '0xd7fdca', FF: '0xcaf0fd', FM: '0xf0cafd'] | |
# MMM: '0xfdc4ca', MMF: '0xfdeaca', MFM: '0xeafdca', MFF: '0xcafdd1', FFF: '0xcafdf7', FFM: '0xcaddfd', FMF: '0xddcafd', FMM: '0xfdcaf7'] | |
# MMMM: '0xfdbaca', MMMF: '0xfdcdca', MMFM: '0xfde0ca', MMFF: '0xfdf3ca', MFMM: '0xf3fdca', MFMF: '0xe0fdca', MFFM: '0xcdfdca', MFFF: '0xcafdda', FFFF: '0xcafded', FFFM: '0xcafafd', FFMF: '0xcae7fd', FFMM: '0xcad4fd', FMFF: '0xd4cafd', FMFM: '0xe7cafd', FMMF: '0xfacafd', FMMM: '0xfdcaed'] | |
# MMMMM: '0xfdb6ca', MMMMF: '0xfdbfca', MMMFM: '0xfdc9ca', MMMFF: '0xfdd2ca', MMFMM: '0xfddcca', MMFMF: '0xfde5ca', MMFFM: '0xfdefca', MMFFF: '0xfdf8ca', MFMMM: '0xf8fdca', MFMMF: '0xeffdca', MFMFM: '0xe5fdca', MFMFF: '0xdcfdca', MFFMM: '0xd2fdca', MFFMF: '0xcafdcc', MFFFM: '0xcafdd5', MFFFF: '0xcafddf', -- FFFFF: '0xcafde8', FFFFM: '0xcafdf2', FFFMF: '0xcafdfb', FFFMM: '0xcaf5fd', FFMFF: '0xcaecfd', FFMFM: '0xcae2fd', FFMMF: '0xcad9fd', FFMMM: '0xcacffd', FMFFF: '0xcfcafd', FMFFM: '0xd9cafd', FMFMF: '0xe2cafd', FMFMM: '0xeccafd', FMMFF: '0xf5cafd', FMMFM: '0xfdcafb', FMMMF: '0xfdcaf2', FMMMM: '0xfdcae8'] | |
# ['0xfdb3ca', '0xfdb8ca', '0xfdbdca', '0xfdc2ca', '0xfdc6ca', '0xfdcbca', '0xfdd0ca', '0xfdd5ca', '0xfdd9ca', '0xfddeca', '0xfde3ca', '0xfde8ca', '0xfdecca', '0xfdf1ca', '0xfdf6ca', '0xfdfbca', '0xfbfdca', '0xf6fdca', '0xf1fdca', '0xecfdca', '0xe8fdca', '0xe3fdca', '0xdefdca', '0xd9fdca', '0xd5fdca', '0xd0fdca', '0xcbfdca', '0xcafdce', '0xcafdd3', '0xcafdd8', '0xcafddc', '0xcafde1', '0xcafde6', '0xcafdeb', '0xcafdef', '0xcafdf4', '0xcafdf9', '0xcafcfd', '0xcaf7fd', '0xcaf3fd', '0xcaeefd', '0xcae9fd', '0xcae4fd', '0xcae0fd', '0xcadbfd', '0xcad6fd', '0xcad1fd', '0xcacdfd', '0xcdcafd', '0xd1cafd', '0xd6cafd', '0xdbcafd', '0xe0cafd', '0xe4cafd', '0xe9cafd', '0xeecafd', '0xf3cafd', '0xf7cafd', '0xfccafd', '0xfdcaf9', '0xfdcaf4', '0xfdcaef', '0xfdcaeb', '0xfdcae6'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment