Color Hollow. A color management module.
Welcome to the G-Golf Color Hollow, partially inspired by the Chickadee’s color module and the Colorways python library.
In G-Golf, a color is a list of 4 floats in the [0 1] range, each representing the value of the RED (r), GREEN (g), BLUE (b) and ALPHA (a) channels, in that order. For example, an opaque red color instance would be ’(1.0 0.0 0.0 1.0).
G-Golf offers several ways to obtain the list representation of a color, in addition to manually listing the values as showned above:
(rgb-cc->color #x73d216) ;; cc = color code ⇒ (0.45 0.82 0.09 1.0) (rgba-cc->color #x73d216aa) ⇒ (0.45 0.82 0.09 0.67)
In the above examples, #x73d216 is the RGB hexadecimal representation of the (opaque) color, and #x73d216aa is the RGBA hexadecimal representation of the same color with an alpha channel value of 0.67 26.
(string->color "deepskyblue") ⇒ (0 3/4 1 1.0) (string->color "#aabbccdd") ⇒ (0.67 0.73 0.8 0.87)
+blue+ ⇒ (0 0 1 1.0) +blanched-almond+ ⇒ (1 23/25 4/5 1.0)
_ Predefined Color Symbols
G-Golf pre-defines color symbols that come from the following color dictionaries:
The file mentioned in the above link is maintained by the GNOME team - composed of (sometimes modified) X11 (rgb.txt) and CSS colors - it is used by both the Pango and the Gdk libraries.
Pre-defined color symbols available in G-Golf are defined by taking
their corresponding color dictionary entry name, substitute any #\Space
by #\-, call g-name->name (which calls
g-studly-caps-expand), then pre and postfix the returned symbol
name using +
. For example:
+antique-white+ ⇒ (49/50 23/25 21/25 1.0) +tango-chocolate-dark+ ⇒ (14/25 7/20 1/100 1.0) +db32-elf-green+ ⇒ (11/50 29/50 43/100 1.0) +rebeccapurple+ ⇒ (2/5 1/5 3/5 1.0)
_ Color Blending
Color blending formulas are mostly taken from here. This is a wip (Work In Progress), as G-Golf currently only provides a few of the numerous color blending modes, to be enhanced in the future.
Unless otherwise specified, color blending procedures (deliberately) apply their formula to the R G B channels (only), and return a (newly allocated) color for which the A (alpha) channel is the base A channel value.
Returns a color, composed of the Red, Green, Blue values for cc (color code), in the [0,1] range, and 1.0 for the Alpha channel.
(rgb-cc->color #x73d216) ⇒ (0.45 0.82 0.09 1.0)
Returns a color, composed of the Red, Green, Blue, Alpha values for cc (color code), in the [0,1] range.
(rgba-cc->color #x73d216aa) ⇒ (0.45 0.82 0.09 0.67)
Returns the color, for str.
A valid str value is either an existing G-Golf color dictionary name entry, or an hexadecimal color string. Accepted hexadecimal color string formats are: ‘#rrggbb’, ‘rrggbb’, ‘#rrggbbaa’ and ‘rrggbbaa’.
(string->color "#73d216aa") ⇒ (0.45 0.82 0.09 0.67)
Returns a (newly allocated) color.
Unless otherwise specified, color blending procedures (deliberately) apply their formula to the R G B channels (only), and return a (newly allocated) color for which the A (alpha) channel is the base A channel value.
The base argument must be a color. The blend argument can either be a color or a float in the [0 1] range (in which case it can also be omited, so as to compute the result of the alternative color blending formula using the default value), for example:
(color-blend 'darken +red+) ⇒ (0.8 0.0 0.0 1.0) (color-blend 'darken +red+ 0.3) ⇒ (0.7 0.0 0.0 1.0) (color-blend 'darken +alice-blue+ +dark-blue+) ⇒ (0 0 11/20 1.0)
The mode argument is a symbol. Currently accepted blending mode and alternative color blending formulas are, applied to each of the R G B channel values:
darken
darken base
⇒ (max 0.0 (- chan (* chan 0.2)))
darken base float
⇒ (max 0.0 (- chan (* chan float)))
darken base blend
⇒ (min base-chan blend-chan)
lighten
lighten base
⇒ (min 1.0 (+ chan (* chan 0.2)))
lighten base float
⇒ (min 1.0 (+ chan (* chan float)))
lighten base blend
⇒ (min base-chan blend-chan)
For those who wouldn’t know, note that both #x73d216 and #x73d216aa expressions are evaluated, as ’#x’ triggers the (predefined) read hash extend procedure for ’x’, that is, the guile reader for hexadecimal values, which returns an integer, the cc (color code).