Colour contrast

Because the contact form has a favourite colour option I thought it would be a fun challenge to auto colour the confirmation emails people receive using their favourite colour Feel free to play around and select different colours to see how it works

As I was building this I realized something interesting The conversion turns a three dimensional value (the colour) into a one dimensional value (the luminance) This means that there are colour which are on opposite sides of the colour wheel but with the same luminance If found those colours would be the worst possible colour combination possible and that's too interesting a puzzle to not take a crack at it

Finding the worst possible colour was an interesting goal and it took a couple attempts to get right At first I pre calculated all possible values of each channel (which I have done here for red, green blue and the value pre multiplication). I also used the contrast value from above and tried to find the three colours that were as dissimilar as possible. The problem was that the algorythm was only optimizing one of the two goals at a time and I needed to try a different approach

Instead of RGB I used hsl (hue, saturation, and lightness) this was much easier to work with because changing hue is how I got the "opposite" colour while lightness is how I gave them the same luminance

Takeaways

  1. contrast is exclusively a matter of how dark or light the colours are and nothing to do with their spot on the colour wheel
  2. Blue is seen as a much darker colour than red and green so if you are trying to fix contrast tweak red and green first
  3. Depending on whether you need a contrast ratio of 3:1 or 4.5:1 you can have up to 4 or 3 colours respectively before some of the colour combinations will be below the given threshold
Dark Mode
Light Mode
Rainbow Mode
Regular Mode
{"JSON"}
**Markdown**
J.W.T
Database