diff options
| author | Protesilaos Stavrou <info@protesilaos.com> | 2023-11-17 07:05:58 +0200 |
|---|---|---|
| committer | Protesilaos Stavrou <info@protesilaos.com> | 2023-11-17 07:05:58 +0200 |
| commit | 41b9acb843d306c7658c55c5bf45c3367ae203f5 (patch) | |
| tree | fdb435d5a902ad586d9402bbe86708ec8a29ff1d | |
| parent | 662495807744faed80dd31e5b5fb29af6dde7226 (diff) | |
Use updated modus-themes formula for contrast tables
I made this change in commit b410fcc in the modus-themes repo. The
idea is to avoid the use of the cl-loop and other cl- functions that
we don't really need.
| -rw-r--r-- | contrast-ratios.org | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/contrast-ratios.org b/contrast-ratios.org index 6fe30c5..b56aea0 100644 --- a/contrast-ratios.org +++ b/contrast-ratios.org @@ -7,20 +7,27 @@ Check this files Git history for updates. Evaluate these snippets, otherwise the tables will not work. Then update a table by typing =C-c C-c= with point at the =#+TBLFM:= line. -#+begin_src emacs-lisp +#+begin_src emacs-lisp :results output silent ;; Copied from my `modus-themes'. ;; This is the WCAG formula to measure relative luminance: ;; <https://www.w3.org/TR/WCAG20-TECHS/G18.html>. +(defun modus-themes--wcag-contribution (channel weight) + "Return the CHANNEL contribution to overall luminance given WEIGHT." + (* weight + (if (<= channel 0.03928) + (/ channel 12.92) + (expt (/ (+ channel 0.055) 1.055) 2.4)))) + (defun modus-themes-wcag-formula (hex) "Get WCAG value of color value HEX. -The value is defined in hexadecimal RGB notation, such as those in -`modus-themes-operandi-colors' and `modus-themes-vivendi-colors'." - (cl-loop for k in '(0.2126 0.7152 0.0722) - for x in (color-name-to-rgb hex) - sum (* k (if (<= x 0.03928) - (/ x 12.92) - (expt (/ (+ x 0.055) 1.055) 2.4))))) +The value is defined in hexadecimal RGB notation, such #123456." + (let ((channels (color-name-to-rgb hex)) + (weights '(0.2126 0.7152 0.0722)) + contribution) + (while channels + (push (modus-themes--wcag-contribution (pop channels) (pop weights)) contribution)) + (apply #'+ contribution))) ;;;###autoload (defun modus-themes-contrast (c1 c2) |
