Simple color library for Common Lisp

cage cc37737fc7 - added Changelog. 1 week ago
.gitignore 755504ba35 gitignore 7 months ago
COPYING 915d7a9015 - added license file. 3 years ago
Changelog cc37737fc7 - added Changelog. 1 week ago
Makefile 89cbb7b24e - added parsing of color names having spaces; 3 years ago
README.org c7203ad692 - updated README. 1 month ago
cl-colors2.asd 3154571f7c - increade version number; 1 month ago
colornames-svg.lisp 2841f8b62e Fixed svg colors denominator, use 255 rather than 256. 1 month ago
colornames-x11.lisp 750dcaa6d7 - fixed "parse-x11-colors.lisp", it uses the new filename 7 months ago
colors.lisp 14b3ca2d6a - fixed compiler macro: 'as-hsv'. 1 week ago
hexcolors.lisp 795aedee59 - [BREAKS API] changed package name from cl-color to cl-colors2 1 year ago
introduction.txt 52f6b91372 first commit 12 years ago
package-template.lisp 3d176434ad - updated 'package-template.lisp'. 7 months ago
package.lisp 6d67230655 svg color names 7 months ago
parse-x11-colors.lisp 750dcaa6d7 - fixed "parse-x11-colors.lisp", it uses the new filename 7 months ago
test.lisp 3154571f7c - increade version number; 1 month ago

README.org

cl-colors: a simple color library for Common Lisp

This is a very simple color library for Common Lisp, providing:

  1. Types for representing colors in HSV and RGB spaces.
  2. Simple conversion functions between the above types (and also
  3. hexadecimal representation for RGB).
  4. Some predefined colors as an association list of names and symbols
  5. which are bound to a corresponding RGB value.
  6. [https://en.wikipedia.org/wiki/X11_color_names][X11 color names]] as
  7. ~*x11-color-list*~
  8. [https://www.w3.org/TR/2018/REC-css-color-3-20180619/#html4][SVG basic color names]]
  9. as ~*svg-colors-list*~
  10. [https://www.w3.org/TR/2018/REC-css-color-3-20180619/#svg-color][SVG extended color names]] as *svg-extended-colors-list*
  11. Example:

#+BEGIN_SRC lisp

'(("lightgreen" . LIGHTGREEN) ("light-green" . LIGHT-GREEN) ("darkred" . DARKRED) …

Examples

#+END_SRC


(let ((color1 (hsv 107 62/100 52/100))  ; greenish
      (color2 (rgb 14/15 26/51 14/15))  ; = violet from X11
      (color3 (as-rgb "ff9e00")))       ; from hexadecimal
  (list                                 ;
   (as-rgb color1)                      ; converting to RGB
   (rgb-combination color1 +blue+ 0.4)  ; HSV autoconverted to RGB
   (hsv-combination color2 +blue+ 0.4)  ; RGB autoconverted to HSV
   color3))

evaluates to


'(#S(RGB :RED 20059/75000 :GREEN 13/25 :BLUE 247/1250)
  #S(RGB :RED 0.160472 :GREEN 0.312 :BLUE 0.51856) ; observe float contagion
  #S(HSV :HUE 60.0 :SATURATION 0.6722689 :VALUE 0.96000004)
  #S(RGB :RED 1 :GREEN 158/255 :BLUE 0))

Observe the float contagion: cl-colors functions don't care about the type of the numbers as long as they are a subtype of real and within the right range.

Documentation

This library is so simple that it does not need a lot of documentation --- just look at the docstring in colors.lisp.

Testing

Run (ql:quickload :cl-colors2/tests).

Regeneration of the X11 color names

Normally you should not need to do this, the sources already contain the autogenerated file colornames.lisp. However, if for some reason you need to regenerate this, you can use make. Even though the library itself does not depend on X11, regenerating this file will require the appropriate file in X11.

Bugs and issues

Please report them on Notabug.

Notes

This is a fork of https://github.com/tpapp/cl-colors, the original author marked it as unsupported.