QUESTION: Can Emacs help a user to pick colors in the form of a 3-element vector, and what does each element of that vector represent?
Background: I borrowed certain sections of code from pong.el
and gamegrid.el
, which use a color format of a 3-element vector. At the time this question was initially written, I had never seen colors specified in that format before -- I wanted to use the same system, but had no idea how a particular color could be selected. The following example places four (4) overlays at the beginning of the buffer, but requires a version of Emacs that supports displaying XPM images:
(let* (
(counter 0)
xpm-list
(color-list '(
[0 0 0]
[1 1 0]
[1 0 0]
[0.5 0.5 0.5]))
(form-feed-xpm
"/* XPM */
static char * form_feed_xpm[] = {
\"11 20 5 1\",
\" s None\",
\"+ s col1\",
\". s col2\",
\"% s col3\",
\"@ s purple\",
\"%%%%%%%%%%%\",
\"%.........%\",
\"%.........%\",
\"%.........%\",
\"%.........%\",
\"%...++++++%\",
\"%.++.++...%\",
\"%+...+....%\",
\"%+...+....%\",
\"%+...+....%\",
\"%+...++++.%\",
\"%....+....%\",
\"%...++....%\",
\"%...+.....%\",
\"%.++++....%\",
\"%.........%\",
\"%.........%\",
\"%.........%\",
\"%.........%\",
\"%%%%%%%%%%%\"};")
(set-color (lambda (color shade)
(let* ((v (floor (* shade 255)))
(r (* v (aref color 0)))
(g (* v (aref color 1)))
(b (* v (aref color 2))))
(format "#%02x%02x%02x" r g b))))
(make-image
(lambda (color)
(let* (
(col1 (funcall set-color color 0.6))
(col2 (funcall set-color color 0.8))
(col3 (funcall set-color color 1.0))
(data `((:type xpm :data ,form-feed-xpm :ascent center
:color-symbols
(("col1" . ,col1)("col2" . ,col2) ("col3" . ,col3)))))
(image (find-image data)) )
(push image xpm-list)))) )
(mapcar
(lambda (x)
(funcall make-image x))
color-list)
(mapcar
(lambda (x)
(overlay-put
(make-overlay
(+ (point-min) counter) (+ (point-min) (1+ counter)))
'display x)
(setq counter (1+ counter)))
(reverse xpm-list)))
pong.el
andgamegrid.el
, except that I am placing overlays instead of text-properties and I am not using thebuffer-display-table
as a warehouse to store XPM images for later usage.