HSL Colours
-
I'm working with material design colour palettes and these are usually represented as HSL. So I added wrappers around the JUCE to/from HSL functions.
The hue value is normalised, so if the palette you're working with provides the hue in degrees you'll need to divide it by 360 when passing it to the
Colours.fromHsl
function. -
Here is a fun little snippet. There are two main functions, and a couple of helper functions.
The main functions are
generatePalette
. You pass it a single colour and it will create a range of shades, similar to the material design examples. The saturation and hue are adjusted automatically to give a pleasing colour scale.In the image below this function is used to create the palette strip with the numbers below it added in a panel's paint routine.
The second function is
getTextColour
This one is for getting a colour that will be drawn over another colour. It takes a base colour, the background colour, and the shade index (between 0 - 1). This should work nicely when moving between light or dark themes.In the image the two panels with "This is some text" both have the same text colour set, the only difference is the background colour property and the function above chooses a shade of the text colour that stands out on the background.
I was following a lot of info from this article (although it doesn't use HSL so I had to adapt) - https://matthewstrom.com/writing/generating-color-palettes/
HiseSnippet 1501.3oc4XstaaaCElJIpK1aEXEaO.b9WJstt9VbRZVwbttFrlVi5rhAjk0QKQaQTYRCI55XLTf9hUf8Hs2fryQTxV9RR6xV+0LbjMOW+32g9PxzJT4xihTgDq7mMd.mX8U1sGK09G3yDRxIGRr9FaWUfZXXKV.Wq4mwizj8GOfEEw8HVVq9ingV4ViD+5u9g8YALoKepHB4UJgK+Yh9B8TosZ9ShffiYd7yD8yXc8lm3pjGDmRh0p1kICXtug0i+bFZ1J1jmxh7IV22t7lM37sp00yiUqlWiFM1Y6cpuSEV2x0YcpzXm5UquU0s2pKw5NG4Izpv1ZllGQrVaek2319pQRSBdkHRzIfiCpPZCY1H9XUfGNEQojC7EAdsRYqHBDkVS4tUMb22ZepvSLQ9TN7qiUPm5QVBzZkYg2py.uJYgW4LvaIPxJCjVy.o6Y21MTLPOUChmuz9DolG1kA0orPwXKYEcN6CTfERco9r2vONDFLwCmFkKWjBO1X274gZUjl9VVHsESxCpPeBM0ydb8Ap9CTRXfSAi5BnOluVJhqaADj9kpgZgj6zcnzUKTRmdaj+OxmCiICBm1WDgw5YJWVv9pgRuHGL0wFLBLfc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