Function: gamegrid-xpm

gamegrid-xpm is a byte-compiled function defined in gamegrid.el.gz.

Signature

(gamegrid-xpm)

Documentation

Generate the XPM format image used for each square.

Source Code

;; Defined in /usr/src/emacs/lisp/play/gamegrid.el.gz
;; Example of glyph in XPM format:
;;
;; /* XPM */
;; static char *noname[] = {
;; /* width height ncolors chars_per_pixel */
;; \"16 16 3 1\",
;; /* colors */
;; \"+ s col1\",
;; \". s col2\",
;; \"- s col3\",
;; /* pixels */
;; \"---------------+\",
;; \"--------------++\",
;; \"--............++\",
;; \"--............++\",
;; \"--............++\",
;; \"--............++\",
;; \"--............++\",
;; \"--............++\",
;; \"--............++\",
;; \"--............++\",
;; \"--............++\",
;; \"--............++\",
;; \"--............++\",
;; \"--............++\",
;; \"-+++++++++++++++\",
;; \"++++++++++++++++\"
;; };

(defun gamegrid-xpm ()
  "Generate the XPM format image used for each square."
  (let* ((glyph-pixel-count (gamegrid-calculate-glyph-size))
         (border-pixel-count (/ glyph-pixel-count 8))
         (center-pixel-count (- glyph-pixel-count (* border-pixel-count 2))))
    (with-temp-buffer
      (insert (format "\
/* XPM */
static char *noname[] = {
/* width height ncolors chars_per_pixel */
\"%s %s 3 1\",
/* colors */
\"+ s col1\",
\". s col2\",
\"- s col3\",
/* pixels */
" glyph-pixel-count glyph-pixel-count))

      (dotimes (row border-pixel-count)
        (let ((edge-pixel-count (+ row 1)))
          (insert "\"")
          (dotimes (_ (- glyph-pixel-count edge-pixel-count)) (insert "-"))
          (dotimes (_ edge-pixel-count) (insert "+"))
          (insert "\",\n")))

      (let ((middle (format "\"%s%s%s\",\n"
                            (make-string border-pixel-count ?-)
                            (make-string center-pixel-count ?.)
                            (make-string border-pixel-count ?+))))
        (dotimes (_ center-pixel-count) (insert middle)))

      (dotimes (row border-pixel-count)
        (let ((edge-pixel-count (- border-pixel-count row 1)))
          (insert "\"")
          (dotimes (_ edge-pixel-count) (insert "-"))
          (dotimes (_ (- glyph-pixel-count edge-pixel-count)) (insert "+"))
          (insert "\"")
          (if (/= row (1- border-pixel-count))
              (insert ",\n")
            (insert "\n};\n"))))
      (buffer-string))))