x11-colors

  1. x11-colors
    1. Description
    2. Author
    3. Maintainer
    4. Repository
    5. Requirements
    6. Documentation
    7. Examples
    8. Changelog
    9. License

Description

Named standard colors as available in X11

Author

felix winkelmann

Maintainer

Erik Falor

Repository

https://gitlab.com/erik.falor/x11-colors

Requirements

Documentation

[procedure] (color spec) => vector

spec can be a string or symbol naming a color from the X11 colors database, a list or vector of 3 integers, or a hex string of the form "#RRGGBB".

Returns a 3-vector #(R G B) where R G B are integers [0, 255].

[procedure] (color->hex-string spec)

spec can be a string or symbol naming a color from the X11 colors database, a list or vector of 3 integers, or a hex string of the form "#RRGGBB".

Returns a hex string of the form "#RRGGBB".

[procedure] (hex-string->color RRGGBB)

Given a hex string of the form "#RRGGBB" returns a 3-vector #(R G B) where R G B are integers [0, 255].

[procedure] (color->name-or-hex-string color)

Given a 3-vector #(R G B), if that color is present in the X11 database return its name as a string; otherwise, return a hex string of the form "#RRGGBB".

Examples

(import x11-colors)

; create color objects from various forms of input
(color 'red)
(color "magenta")
(color #(102 51 153))
(color '(244 102 255))
(color "#ffff00")

; create hex strings of the form "#RRGGBB"
(color->hex-string 'red)
(color->hex-string "magenta")
(color->hex-string #(102 51 153))
(color->hex-string '(244 102 255))
(color->hex-string "#ffff00")

; convert a hex string "#RRGGBB" into a color vector
(hex-string->color "#8b4789")

; retrieve the name of a color...
(color->name-or-hex-string #(102 51 153))

; ...or display a hex string "#RRGGBB" if it doesn't have a name in the X11 database
(color->name-or-hex-string #(102 50 153))

Changelog

License

BSD
Copyright (C) 2020, Felix Winkelmann
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer. 
Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution. 
Neither the name of the author nor the names of its contributors may be
used to endorse or promote products derived from this software without
specific prior written permission. 
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.