|
1 | 1 | ;;; fireplace.el --- A cozy fireplace for emacs -*- lexical-binding: t; -*- |
2 | 2 |
|
3 | 3 | ;; Copyright (C) 2015 Johan Sivertsen |
4 | | -;;; Version: 1.0 |
| 4 | +;;; Version: 1.1 |
5 | 5 | ;;; Author: Johan Sivertsen <[email protected]> |
6 | 6 | ;;; URL: https://github.com/johanvts/emacs-fireplace |
7 | 7 | ;;; Released: December 2015 |
|
62 | 62 | "Default name for fireplace buffer." |
63 | 63 | :type 'string :group 'fireplace) |
64 | 64 |
|
65 | | -;; Program controlled variables |
66 | | - |
| 65 | +;;; Faces |
| 66 | +(defgroup fireplace-faces nil |
| 67 | + "Faces for `fireplace'." |
| 68 | + :group 'fireplace) |
| 69 | + |
| 70 | +(defface fireplace-outter-flame-face |
| 71 | + '((t (:background "orange red"))) |
| 72 | + "Color of the core of the flame." |
| 73 | + :group 'fireplace-faces) |
| 74 | + |
| 75 | +(defface fireplace-inner-flame-face |
| 76 | + '((t (:background "dark orange"))) |
| 77 | + "Color of the core of the flame." |
| 78 | + :group 'fireplace-faces) |
| 79 | +(defface fireplace-smoke-face |
| 80 | + '((t (:foreground "slate grey"))) |
| 81 | + "Color of the smoke." |
| 82 | + :group 'fireplace-faces) |
| 83 | + |
| 84 | +;;; Program controlled variables |
67 | 85 | (defvar fireplace--bkgd-height "Used for fireplace height, will be set from windows size") |
68 | 86 | (defvar fireplace--bkgd-width "Used for fireplace width, will be set from windows size") |
69 | 87 | (defvar fireplace--timer "Holds the active fireplace, kill using fireplace-off") |
70 | 88 | (defvar fireplace--flame-width "Calculated width of flames") |
71 | 89 |
|
72 | | -;; Helper routines |
| 90 | +;;; Helper routines |
73 | 91 |
|
74 | 92 | (defun fireplace--make-grid () |
75 | 93 | "Redraw backgound of buffer." |
|
88 | 106 | "Draw flame stripe." |
89 | 107 | (fireplace--gotoxy x y) |
90 | 108 | (let* ((actual-width (min width (1+ (- fireplace--bkgd-width x)))) |
91 | | - (hot-core (/ actual-width 2))) |
| 109 | + (hot-core (/ actual-width 2))) |
92 | 110 | (delete-char actual-width) |
93 | 111 | (insert (propertize (make-string actual-width fireplace-fill-char) |
94 | | - 'face `(:background ,"orange red"))) |
| 112 | + 'face 'fireplace-outter-flame-face)) |
95 | 113 | (when (> hot-core 1) |
96 | 114 | (fireplace--gotoxy (+ x (/ hot-core 2)) y) |
97 | 115 | (delete-char hot-core) |
98 | 116 | (insert (propertize (make-string hot-core fireplace-fill-char) |
99 | | - 'face `(:background ,"dark orange")))))) |
| 117 | + 'face 'fireplace-inner-flame-face))))) |
100 | 118 |
|
101 | 119 | (defun fireplace--smoke (x height) |
102 | 120 | "Draw one random smoke." |
103 | | - (fireplace--gotoxy (if (>(random 3) 1) |
| 121 | + (fireplace--gotoxy |
| 122 | + (if (>(random 3) 1) |
104 | 123 | (+ x (random (/ fireplace--bkgd-width 5))) |
105 | | - (max 0 (- x (random (/ fireplace--bkgd-width 5))))) |
| 124 | + (max 0 (- x (random (/ fireplace--bkgd-width 5))))) |
106 | 125 | (+ height (random (- fireplace--bkgd-height height)))) |
107 | 126 | (delete-char 1) |
108 | 127 | (insert (propertize (make-string 1 fireplace-smoke-char) |
109 | | - 'face `(:foreground, "slate grey")))) |
| 128 | + 'face 'fireplace-smoke-face))) |
110 | 129 |
|
111 | 130 | (defun fireplace--flame (middle h) |
112 | 131 | "Draw a flame." |
113 | 132 | (setq cursor-type nil) |
114 | 133 | (let* ((width h) |
115 | | - (lower (truncate(* 0.2 h))) |
116 | | - (high (- h lower)) |
117 | | - x |
118 | | - line) |
| 134 | + (lower (truncate (* 0.2 h))) |
| 135 | + (high (- h lower)) |
| 136 | + x |
| 137 | + line) |
119 | 138 | (dotimes (y lower) |
120 | 139 | (setq width (+ width y) |
121 | 140 | x (- middle (/ width 2))) |
|
126 | 145 | (setq width (- fireplace--bkgd-width x))) |
127 | 146 | (draw-flame-stripe x y width)) |
128 | 147 | (dotimes (y high) |
129 | | - (setq line (+ lower y)) |
130 | | - (setq width (max 0 (- width 1 (random 3)))) |
131 | | - (setq x (- middle (/ width 2))) |
| 148 | + (setq line (+ lower y) |
| 149 | + width (max 0 (- width 1 (random 3))) |
| 150 | + x (- middle (/ width 2))) |
132 | 151 | (when (< x 0) |
133 | 152 | (setq width (+ width x) |
134 | 153 | x 0)) |
|
144 | 163 | (fireplace--make-grid) |
145 | 164 | (dolist (pos flame-pos) |
146 | 165 | (fireplace--flame (round (* pos fireplace--bkgd-width)) |
147 | | - (+ |
148 | | - (round (* (+ 0.2 (min pos (- 1 pos))) flame-width)) |
149 | | - (random 3)))) |
| 166 | + (+ (round (* (+ 0.2 (min pos (- 1 pos))) flame-width)) |
| 167 | + (random 3)))) |
150 | 168 | (setq buffer-read-only t))) |
151 | 169 |
|
152 | 170 |
|
|
188 | 206 | (defun fireplace-toggle-smoke () |
189 | 207 | "Toggle smoke on/off." |
190 | 208 | (interactive) |
191 | | - (if fireplace-smoke-on |
192 | | - (setq fireplace-smoke-on nil) |
193 | | - (setq fireplace-smoke-on t))) |
| 209 | + (setq fireplace-smoke-on (not fireplace-smoke-on))) |
194 | 210 |
|
195 | 211 | ;;; Key-bindings |
196 | 212 |
|
|
0 commit comments