xxxxxxxxxx
20
p5.prototype._sRGBtoLuminance = function (value) {
return value <= 0.03928 ? value / 12.921 : ((value + 0.055) / 1.055) ** 2.4;
};
p5.prototype.luminance = function (c) {
const [r, g, b] = c.levels.map((val) => this._sRGBtoLuminance(val / 255));
return 0.2126 * r + 0.7152 * g + 0.0722 * b;
};
p5.prototype.contrast = function (c1, c2) {
const l1 = this.luminance(c1) + 0.05;
const l2 = this.luminance(c2) + 0.05;
return l1 > l2 ? l1 / l2 : l2 / l1;
};
function setup() {
const contrastTest = contrast(color(255), color("#0000ff"));
console.log(contrastTest);
}