diff --git a/src/color/p5.Color.js b/src/color/p5.Color.js index d258bf10e2..185a703aeb 100644 --- a/src/color/p5.Color.js +++ b/src/color/p5.Color.js @@ -8,6 +8,7 @@ import { RGB, RGBHDR, HSL, HSB, HWB, LAB, LCH, OKLAB, OKLCH } from './creating_reading'; + import { ColorSpace, to, @@ -25,7 +26,7 @@ import { OKLab, OKLCH as OKLCHSpace, - + contrast, P3 } from 'colorjs.io/fn'; import HSBSpace from './color_spaces/hsb.js'; @@ -41,6 +42,9 @@ const map = (n, start1, stop1, start2, stop2, clamp) => { const serializationMap = {}; + + + class Color { // Reference to underlying color object depending on implementation // Not meant to be used publicly unless the implementation is known for sure @@ -290,6 +294,34 @@ class Color { } return colorString; } +/** + * Checks if two colors contrast ratio is WCAG 2.1 compliant and returns the ratio + * + * @param {Color} other + * @returns {{ ratio: Number, passes: boolean }} + * @example + *
+ *
+ * function setup() {
+ * // Define colors
+ * let color1 = color(255, 255, 255);
+ * let color2 = color(0);
+ *
+ * // Test for contrast
+ * let result = color1.contrast(color2)
+ *
+ * console.log(result)
+ *
+ * }
+ *
+ *