You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Checks the contrast between two colors. This method returns a boolean
336
+
* value to indicate if the two color has enough contrast. `true` means that
337
+
* the colors has enough contrast to be used as background color and body
338
+
* text color. `false` means there is not enough contrast.
339
+
*
340
+
* A second argument can be passed to the method, `options` , which defines
341
+
* the algorithm to be used. The algorithms currently supported are
342
+
* WCAG 2.1 (`'WCAG21'`) or APCA (`'APCA'`). The default is WCAG 2.1. If a
343
+
* value of `'all'` is passed to the `options` argument, an object containing
344
+
* more details is returned. The details object will include the calculated
345
+
* contrast value of the colors and different passing criteria.
346
+
*
347
+
* For more details about color contrast, you can checkout this page from
348
+
* color.js. The WebAIM color contrast checker is a good tool to check out as
349
+
* well.
354
350
*
355
351
* @param {Color} other
356
-
* @returns {{ ratio: Number }}
352
+
* @returns {boolean|object}
357
353
* @example
358
354
* <div>
359
355
* <code>
360
-
*
361
-
* // The contrast checker can be used both during development
362
-
* // with `print()`, or to help select readable colors on the fly.
363
-
* // This example shows both uses.
364
-
*
365
-
* let bgColor;
366
-
* let fg1Color;
367
-
* let fg2Color;
368
-
*
356
+
* let bgColor, fg1Color, fg2Color, msg1, msg2;
369
357
* function setup() {
370
358
* createCanvas(100, 100);
371
359
* bgColor = color(0);
372
-
* fg1Color = color(120);
373
-
* fg2Color = color(255);
374
-
*
375
-
* describe('A small square canvas with acentered text outlined by a thick stroke. The text reads 'click again!'. On every mouse click, the background, square outline, and text colors randomize, with high enough contrast for readability.');
360
+
* fg1Color = color(100);
361
+
* fg2Color = color(220);
362
+
*
363
+
* if(bgColor.contrast(fg1Color)){
364
+
* msg1 = 'good';
365
+
* }else{
366
+
* msg1 = 'bad';
367
+
* }
368
+
*
369
+
* if(bgColor.contrast(fg2Color)){
370
+
* msg2 = 'good';
371
+
* }else{
372
+
* msg2 = 'bad';
373
+
* }
374
+
*
375
+
* describe('A black canvas with a faint grey word saying "bad" at the top left and a brighter light grey word saying "good" in the middle of the canvas.');
376
376
* }
377
-
*
378
-
* function draw(){
377
+
*
378
+
* function draw(){
379
379
* background(bgColor);
380
-
* stroke(fg1Color);
381
-
* noFill();
382
-
* strokeWeight(5);
383
-
* rect(10, 10, 80, 80);
384
-
*
385
-
* noStroke();
380
+
*
381
+
* textSize(18);
382
+
*
383
+
* fill(fg1Color);
384
+
* text(msg1, 10, 30);
385
+
*
386
386
* fill(fg2Color);
387
-
* textAlign(CENTER, CENTER);
388
-
* textSize(20);
389
-
* text("click\nagain!", 50, 50);
387
+
* text(msg2, 10, 60);
390
388
* }
391
-
*
392
-
* function mouseClicked(){
393
-
* let newBgColor;
394
-
* let newFg1Color;
395
-
* let newFg2Color;
396
-
*
397
-
* // The loop may go for a long time, but it will not go on forever
398
-
* // It will stop the first time that the random colors contrast enough
0 commit comments