summaryrefslogtreecommitdiff
path: root/scheme
diff options
context:
space:
mode:
author2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2025-04-08 13:33:45 +1000
committer2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2025-04-08 13:33:45 +1000
commite342d2d2dc51677f9727f7117e1746ef2231db0d (patch)
tree6bf6df7eb1bc36d4bc740390133c0c8b4838df12 /scheme
parentscheme: better colours + parallel generation (diff)
downloadcaelestia-cli-e342d2d2dc51677f9727f7117e1746ef2231db0d.tar.gz
caelestia-cli-e342d2d2dc51677f9727f7117e1746ef2231db0d.tar.bz2
caelestia-cli-e342d2d2dc51677f9727f7117e1746ef2231db0d.zip
scheme: better primary colour
Primary colour is used for layers + accents Get highest scored bright colour instead of just highest scored
Diffstat (limited to 'scheme')
-rwxr-xr-xscheme/autoadjust.py6
-rwxr-xr-xscheme/score.py21
2 files changed, 19 insertions, 8 deletions
diff --git a/scheme/autoadjust.py b/scheme/autoadjust.py
index 73deb88..294c33f 100755
--- a/scheme/autoadjust.py
+++ b/scheme/autoadjust.py
@@ -164,13 +164,13 @@ def get_scheme(scheme: str) -> DynamicScheme:
if __name__ == "__main__":
light = sys.argv[1] == "light"
scheme = sys.argv[2]
- colours_in = sys.argv[3]
+ colours_in = sys.argv[3].split(" ")
base = light_colours if light else dark_colours
chroma_mult = 1.5 if light else 1.2
# Convert to HLS
- colours = [hex_to_hls(c) for c in colours_in.split(" ")]
+ colours = [hex_to_hls(c) for c in colours_in[1:]]
# Sort colours and turn into dict
colours = smart_sort(colours, base)
@@ -200,7 +200,7 @@ if __name__ == "__main__":
# Layers and accents
material = {}
- primary_scheme = MatScheme(Hct.from_int(int(f"0xFF{colours_in.split(" ")[0]}", 16)), not light, 0)
+ primary_scheme = MatScheme(Hct.from_int(int(f"0xFF{colours_in[0]}", 16)), not light, 0)
for colour in vars(MaterialDynamicColors).keys():
colour_name = getattr(MaterialDynamicColors, colour)
if hasattr(colour_name, "get_hct"):
diff --git a/scheme/score.py b/scheme/score.py
index 49464a2..531046f 100755
--- a/scheme/score.py
+++ b/scheme/score.py
@@ -44,6 +44,7 @@ class Score:
neighbor_hue = int(sanitize_degrees_int(i))
hue_excited_proportions[neighbor_hue] += proportion
+ # Score colours
scored_hct = []
for hct in colors_hct:
hue = int(sanitize_degrees_int(round(hct.hue)))
@@ -67,6 +68,7 @@ class Score:
scored_hct.sort(key=lambda x: x["score"], reverse=True)
+ # Choose distinct colours
chosen_colors = []
for difference_degrees_ in range(90, 0, -1):
chosen_colors.clear()
@@ -82,23 +84,32 @@ class Score:
if len(chosen_colors) >= desired:
break
- colors = []
+ # Get primary colour
+ got_primary = False
+ for cutoff in range(20, 0, -1):
+ for item in scored_hct:
+ if item["hct"].chroma > cutoff and item["hct"].tone > cutoff * 3:
+ chosen_colors.insert(0, item["hct"])
+ got_primary = True
+ break
+ if got_primary:
+ break
+ # Fix disliked colours
if dislike_filter:
for chosen_hct in chosen_colors:
chosen_colors[chosen_colors.index(chosen_hct)] = (
DislikeAnalyzer.fix_if_disliked(chosen_hct)
)
- for chosen_hct in chosen_colors:
- colors.append(chosen_hct.to_int())
- return colors
+
+ return chosen_colors
if __name__ == "__main__":
img = sys.argv[1]
colours = ImageQuantizeCelebi(img, 1, 128)
- colours = [Hct.from_int(c).to_rgba()[:3] for c in Score.score(colours)]
+ colours = [c.to_rgba()[:3] for c in Score.score(colours)]
# print("".join(["\x1b[48;2;{};{};{}m \x1b[0m".format(*colour) for colour in colours]))
print(" ".join(["{:02X}{:02X}{:02X}".format(*colour) for colour in colours]))