diff options
| author | Freya Murphy <freya@freyacat.org> | 2026-03-16 23:46:49 -0400 |
|---|---|---|
| committer | Freya Murphy <freya@freyacat.org> | 2026-03-17 14:19:50 -0400 |
| commit | 25b4f61512a76d75aa94b44bb666fd899cf8bf5e (patch) | |
| tree | b97a4dd9190cf57b2c0c6408bf292b6e214505b7 /lib/colors.nix | |
| parent | update commits (diff) | |
| download | dotfiles-nix-25b4f61512a76d75aa94b44bb666fd899cf8bf5e.tar.gz dotfiles-nix-25b4f61512a76d75aa94b44bb666fd899cf8bf5e.tar.bz2 dotfiles-nix-25b4f61512a76d75aa94b44bb666fd899cf8bf5e.zip | |
update caelestia and its theming
Diffstat (limited to 'lib/colors.nix')
| -rw-r--r-- | lib/colors.nix | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/lib/colors.nix b/lib/colors.nix new file mode 100644 index 0000000..a653f11 --- /dev/null +++ b/lib/colors.nix @@ -0,0 +1,66 @@ +{lib, ...}: let + colorToInt = hex: let + table = { + "0" = 0; + "1" = 1; + "2" = 2; + "3" = 3; + "4" = 4; + "5" = 5; + "6" = 6; + "7" = 7; + "8" = 8; + "9" = 9; + "a" = 10; + "b" = 11; + "c" = 12; + "d" = 13; + "e" = 14; + "f" = 15; + }; + in + builtins.foldl' + (acc: c: acc * 16 + table.${c}) + 0 + (lib.strings.stringToCharacters (lib.strings.toLower hex)); + + colorToHex = n: let + hexChars = "0123456789abcdef"; + hi = builtins.div n 16; + lo = lib.trivial.mod n 16; + in + builtins.substring hi 1 hexChars + + builtins.substring lo 1 hexChars; + + mapColor = f: hex: let + r = colorToInt (builtins.substring 0 2 hex); + g = colorToInt (builtins.substring 2 2 hex); + b = colorToInt (builtins.substring 4 2 hex); + in + colorToHex (f r) + + colorToHex (f g) + + colorToHex (f b); + + darkenColor = factor: hex: + mapColor (c: builtins.floor (c * (1 - factor))) hex; + + lightenColor = factor: hex: + mapColor (c: builtins.floor (c + (255 - c) * factor)) hex; + + mixColor = factor: hex1: hex2: let + r1 = colorToInt (builtins.substring 0 2 hex1); + g1 = colorToInt (builtins.substring 2 2 hex1); + b1 = colorToInt (builtins.substring 4 2 hex1); + r2 = colorToInt (builtins.substring 0 2 hex2); + g2 = colorToInt (builtins.substring 2 2 hex2); + b2 = colorToInt (builtins.substring 4 2 hex2); + r = builtins.floor (r1 * factor) + builtins.floor (r2 * (1 - factor)); + g = builtins.floor (g1 * factor) + builtins.floor (g2 * (1 - factor)); + b = builtins.floor (b1 * factor) + builtins.floor (b2 * (1 - factor)); + in + colorToHex r + + colorToHex g + + colorToHex b; +in { + inherit colorToInt colorToHex darkenColor lightenColor mixColor; +} |