Function: bubbles--initialize-images
bubbles--initialize-images is a byte-compiled function defined in
bubbles.el.gz.
Signature
(bubbles--initialize-images)
Documentation
Prepare images for playing bubbles.
Source Code
;; Defined in /usr/src/emacs/lisp/play/bubbles.el.gz
(defun bubbles--initialize-images ()
"Prepare images for playing `bubbles'."
(when (and (display-images-p)
(not (eq bubbles-graphics-theme 'ascii)))
(let ((template (pcase bubbles-graphics-theme
('circles bubbles--image-template-circle)
('balls bubbles--image-template-ball)
('squares bubbles--image-template-square)
('diamonds bubbles--image-template-diamond)
('emacs bubbles--image-template-emacs))))
(setq bubbles--empty-image
(create-image (replace-regexp-in-string
"^\"\\(.*\\)\t.*c .*\",$"
"\"\\1\tc None\"," template)
'xpm t
;;:mask 'heuristic
:margin '(2 . 1)))
(setq bubbles--images
(mapcar (lambda (color)
(let* ((rgb (color-values color))
(red (nth 0 rgb))
(green (nth 1 rgb))
(blue (nth 2 rgb)))
(with-temp-buffer
(insert template)
(goto-char (point-min))
(re-search-forward
"^\"[0-9]+ [0-9]+ \\(.*?\\) .*\",$" nil t)
(goto-char (point-min))
(while (re-search-forward
"^\"\\(.*\\)\t.*c \\(#.*\\)\",$" nil t)
(let* ((crgb (color-values (match-string 2)))
(r (nth 0 crgb))
(g (nth 1 crgb))
(b (nth 2 crgb))
(brightness (/ (+ r g b) 3.0 256 256))
(val (sin (* brightness (/ float-pi 2))))
(rr (* red val))
(gg (* green val))
(bb (* blue val))
;;(rr (/ (+ red r) 2))
;;(gg (/ (+ green g) 2))
;;(bb (/ (+ blue b) 2))
(color (format "#%02x%02x%02x"
(/ rr 256) (/ gg 256)
(/ bb 256))))
(replace-match (format "\"\\1\tc %s\","
(upcase color)))))
(create-image (buffer-string) 'xpm t
:margin '(2 . 1)
;;:mask 'heuristic
))))
(bubbles--colors))))
;; check images
(setq bubbles--images-ok bubbles--empty-image)
(mapc (lambda (elt)
(setq bubbles--images-ok (and bubbles--images-ok elt)))
bubbles--images)))