-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Title: Elisp To Compute Contrast Ratio? #2
Comments
When I started the project ~1 year ago, I relied on my own bash script that implements the WCAG formula. Now I prefer this Elisp solution: ;; Code is courtesy of Omar Antolín Camarena:
;; https://github.com/oantolin/emacs-config
(defun wcag (hex)
(apply #'+
(cl-mapcar
(lambda (k x)
(* k (if (<= x 0.03928)
(/ x 12.92)
(expt (/ (+ x 0.055) 1.055) 2.4))))
'(0.2126 0.7152 0.0722)
(color-name-to-rgb hex))))
(defun clr (c1 c2)
(let ((ct (/ (+ (wcag c1) 0.05)
(+ (wcag c2) 0.05))))
(max ct (/ ct)))) You can then combine that with Org's tables. Such as what I have on this blog post: https://protesilaos.com/codelog/2020-07-04-modus-themes-faint-colours/ (I am not particularly good with Org tables, but those work). Note that Emacs also has the |
nice. perhaps check it in somewhere? I'm going to add it to my emacspeak
repo so I have it somewhere.
--
Thanks,
…--Raman
♈ Id: kg:/m/0285kf1 🦮
|
Please let me know how I can check it in and I shall do it. |
I meant check it into the modus-theme repo -- perhaps create a utils
directory there?
--
Thanks,
…--Raman
♈ Id: kg:/m/0285kf1 🦮
|
The code is not mine and I would prefer not to include extras in the themes' repo. Can I send it to you via email? Is your address the one you have in your resume? |
yes. I already took what you sent by email and stashed it away, but not
sure if you have something cleaned up for color contrast.
--
Thanks,
…--Raman
♈ Id: kg:/m/0285kf1 🦮
|
Hello there @tvraman -- I have a function for computing contrast levels in my recently created emacs package color-tools.el. It will (hopefully) make it to melpa soon. |
Just to add that the latest version of the themes does include the functions that implement the WCAG formula for colour contrast: ;; This is the WCAG formula: https://www.w3.org/TR/WCAG20-TECHS/G18.html
(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)))))
;;;###autoload
(defun modus-themes-contrast (c1 c2)
"Measure WCAG contrast ratio between C1 and C2.
C1 and C2 are color values written in hexadecimal RGB."
(let ((ct (/ (+ (modus-themes-wcag-formula c1) 0.05)
(+ (modus-themes-wcag-formula c2) 0.05))))
(max ct (/ ct)))) That granted, color-tools.el provides a lot of useful features and should be the one to use: I will be using it as well (thanks @neeasade for that!). |
thanks for the heads-up, look forward to your color-tools package.
--
Thanks,
…--Raman
♈ Id: kg:/m/0285kf1 🦮
|
Description: Emacs has some elisp libraries for color conversion among
various color coordinates, and there is the excellent name-this-color
package on melpa. However, none of these can compute contrast ratio
best I can tell. So how are you doing this for the modus themes? If
it's there and I'm missing it, I'd like a pointer; otherwise it would
be nice to have an elisp contrast compute function so that over time,
other theme authors can at least verify if their color contrasts are
good for accessibility.
The text was updated successfully, but these errors were encountered: