Mischback / colorizer

A simple web-based colorscheme builder which focuses on contrast values.
https://mischback.github.io/colorizer/
MIT License
1 stars 0 forks source link

[Experimental] Contrast Calculation #34

Open Mischback opened 1 year ago

Mischback commented 1 year ago

WCAG2.0 calculates the contrast ratio between two colors depending on their relative luminance.

The relative luminance is calculated like this:

  luminance: function(red, green, blue) {
    var a = [red, green, blue].map(function(v) {
      v /= 255;
      return v <= 0.04045
        ? v / 12.92
        : Math.pow((v+0.055) / 1.055, 2,4);
    });
    return a[0] * 0.2126 + a[1] * 0.7152 + a[2] * 0.0722;
  },

However, this article states, that the Y of XYZ corresponds to the relative luminance already.

Experiment

Define two colors (a, b) in sRGB colorspace. Calculate their contrast ratio in sRGB using the functions of WCAG2.0 and then use their corresponding XYZ representations to calculate the contrast ratio depending on Y alone.

Result

As of https://github.com/Mischback/colorizer/commit/28b7d7b70542a6245b87a74626d3c9c0e29b2302

So What?