From f12590643eb86dbcec043abd385c60ebda306a5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20H=C3=B8jberg?= Date: Wed, 12 Jan 2022 10:27:55 -0500 Subject: [PATCH] Hashvatar: use background hue for tendrils When picking the tendril color for the `Hashvatar`, pick one in the same hue as the background color. To support this add a `Hue` type to `Color` to help determine what hue a `Color` is in. --- src/Hashvatar.elm | 2 +- src/UI/Color.elm | 92 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+), 1 deletion(-) diff --git a/src/Hashvatar.elm b/src/Hashvatar.elm index fab9547..b09774e 100644 --- a/src/Hashvatar.elm +++ b/src/Hashvatar.elm @@ -71,7 +71,7 @@ toGrid slots = selectTendrils grid_ = let tendrils = - getIn grid_.tendrils (Color.harmonizesWith grid_.background) + getIn grid_.tendrils (Color.inSameHue grid_.background) in Maybe.map (\tr -> diff --git a/src/UI/Color.elm b/src/UI/Color.elm index 794f993..2000e32 100644 --- a/src/UI/Color.elm +++ b/src/UI/Color.elm @@ -102,6 +102,98 @@ filterLuminance pred colors_ = +-- Hue + + +type Hue + = Gray + | Orange + | Pink + | Purple + | Blue + | Green + + +hueOf : Color -> Hue +hueOf color = + if isGray color then + Gray + + else if isOrange color then + Orange + + else if isPink color then + Pink + + else if isPurple color then + Purple + + else if isBlue color then + Blue + + else + Green + + +{-| Get all the other colors in the same hue as the given color +-} +inSameHue : Color -> List Color +inSameHue color = + let + sameHue = + case hueOf color of + Gray -> + grays + + Orange -> + oranges + + Pink -> + pinks + + Purple -> + purples + + Blue -> + blues + + Green -> + greens + in + List.filter (\c -> c /= color) sameHue + + +isGray : Color -> Bool +isGray color = + List.member color grays + + +isOrange : Color -> Bool +isOrange color = + List.member color oranges + + +isPink : Color -> Bool +isPink color = + List.member color pinks + + +isPurple : Color -> Bool +isPurple color = + List.member color purples + + +isBlue : Color -> Bool +isBlue color = + List.member color blues + + +isGreen : Color -> Bool +isGreen color = + List.member color greens + + + -- Grays