GitHub - neeasade/color-tools.el: color tools for emacs
source link: https://github.com/neeasade/color-tools.el
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Utilities for tweaking colors with properties from various color spaces. Visualized in this blog post, used to create tarps.
Installation
Install with straight.el:
(straight-use-package '(color-tools :host github :repo "neeasade/color-tools.el" :branch "master"))
Dependencies
Examples:
Supported color spaces: lab
lch
hsl
hsv
hsluv
hpluv
. Generally, scalar values fall within range 0 to 100 (consistent interface across spaces for the convenience of using this library). Exceptions are: Hue (0 to 360), and the AB values in lab
, which are -100 to 100.
Color creation
(ct-make-lab 50 30 40) ;; => "#b36033" (ct-make-hsl 60 60 70) ;; => "#e0e084"
Color inspection
(ct-get-lab "#b36033") ;; => (49.72678146037228 29.94907362859206 39.78635241058663) (ct-get-lab-b "#b36033") ;; => 39.78635241058663
Color property tweaking
;; complement color by flipping hue: (ct-transform-lch "#b36033" (lambda (L C H) (list L C (+ 180 H)))) ;; => "#0086b9" ;; 1.5x lightness: (ct-transform-lch-l "#b36033" (lambda (L) (* 1.5 L))) ;; => "#fea06f" ;; max chroma (notice you may pass a function or value): (ct-transform-lch-c "#b36033" 100) ;; => "#dc3a00"
Contrast levels
(ct-contrast-ratio "#dddddd" "#222222") ;; => 11.713614348620013 ;; tint to a contrast ratio: (ct-iterate ;; start color "#eeeeee" ;; action 'ct-lab-darken ;; predicate (check contrast against background) (fn (> (ct-contrast-ratio <> "#eeeeee") 4.5))) ;; => "#6c6c6c" ;; sugar for the above: (ct-tint-ratio "#eeeeee" "#eeeeee" 4.5) ;; => "#6c6c6c"
Hue rotation
(ct-rotation-hsluv (ct-make-hsluv 0 50 50) ;; degrees 60) ;; => ("#bb556d" "#887351" "#5d7f51" "#547e78" "#597a97" "#a05dac")
Gotchas
Some colors as defined in color spaces may not be represented in the RGB space (and vice versa). The transformation functions here clamp values going out, but not coming in. One example is the narrowly scoped hpluv
space:
(ct-get-hpluv "#dd00cc") ;; these values are way out of range! ;; => (314.3830496716472 282.01497572464575 51.53528501195089) ;; notice we ask for the same color back, but the transform functions clamp the output to maximum HPL values: (ct-transform-hpluv "#dd00cc" (lambda (H P L) (list H P L))) ;; => "#9f6898"
Testing
Right now testing happens by using the `ct-make-*` functions(these use the transform functions, which make up the basis for all the color space functions) against:
Related (Emacs)
Related (colors)
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK