|
1 | | -;;; fireplace.el --- A cozy fireplace for emacs |
2 | | -;;; Version: 1.0 |
| 1 | +;;; fireplace.el --- A cozy fireplace for emacs -*- lexical-binding: t; -*- |
| 2 | + |
| 3 | +;; Copyright (C) 2015 Johan Sivertsen |
| 4 | +;;; Version: 0.1 |
| 5 | +;;; Author: Johan Sivertsen <[email protected]> |
| 6 | +;;; URL: https://github.com/johanvts/emacs-fireplace |
| 7 | +;;; Released: December 2015 |
| 8 | + |
| 9 | +;; Keywords: games |
| 10 | + |
| 11 | +;; This program is free software; you can redistribute it and/or modify |
| 12 | +;; it under the terms of the GNU General Public License as published by |
| 13 | +;; the Free Software Foundation, either version 3 of the License, or |
| 14 | +;; (at your option) any later version. |
| 15 | + |
| 16 | +;; This program is distributed in the hope that it will be useful, |
| 17 | +;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | +;; GNU General Public License for more details. |
| 20 | + |
| 21 | +;; You should have received a copy of the GNU General Public License |
| 22 | +;; along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 23 | + |
3 | 24 | ;;; Commentary: |
4 | | -;; Author: Johan Sivertsen <[email protected]> |
5 | | -;; URL: https://github.com/johanvts/emacs-fireplace |
6 | | -;; Released: December 2015 |
| 25 | + |
| 26 | +;; Puts your emacs on fire |
7 | 27 |
|
8 | 28 | ;;; Code: |
9 | 29 | ;; User definable Variables |
|
31 | 51 |
|
32 | 52 | ;; Program controlled variables |
33 | 53 |
|
34 | | -(defvar fp-bkgd-height "Used for fireplace height, will be set from windows size") |
35 | | -(defvar fp-bkgd-width "Used for fireplace width, will be set from windows size") |
36 | | -(defvar fp-timer "Holds the active fireplace, kill using fireplace-off") |
37 | | -(defvar fp-flame-width "Calculated width of flames") |
| 54 | +(defvar fireplace--bkgd-height "Used for fireplace height, will be set from windows size") |
| 55 | +(defvar fireplace--bkgd-width "Used for fireplace width, will be set from windows size") |
| 56 | +(defvar fireplace--timer "Holds the active fireplace, kill using fireplace-off") |
| 57 | +(defvar fireplace--flame-width "Calculated width of flames") |
38 | 58 |
|
39 | 59 | ;; Helper routines |
40 | 60 |
|
41 | | -(defun make-grid () |
| 61 | +(defun fireplace--make-grid () |
42 | 62 | (erase-buffer) |
43 | | - (dotimes (i fp-bkgd-height) |
44 | | - (insert-char fireplace-background-char fp-bkgd-width) |
| 63 | + (dotimes (i fireplace--bkgd-height) |
| 64 | + (insert-char fireplace-background-char fireplace--bkgd-width) |
45 | 65 | (newline))) |
46 | 66 |
|
47 | | -(defun gotoxy (x y) |
48 | | - (goto-char (+ 1 x (* (- fp-bkgd-height (+ 1 y)) (+ 1 fp-bkgd-width))))) |
| 67 | +(defun fireplace--gotoxy(x y) |
| 68 | + (goto-char (+ 1 x (* (- fireplace--bkgd-height (+ 1 y)) (+ 1 fireplace--bkgd-width))))) |
49 | 69 |
|
50 | 70 |
|
51 | 71 | (defun draw-flame-stripe (x y width) |
52 | | - (gotoxy x y) |
53 | | - (let* ((actual-width (min width (1+ (- fp-bkgd-width x)))) |
| 72 | + (fireplace--gotoxy x y) |
| 73 | + (let* ((actual-width (min width (1+ (- fireplace--bkgd-width x)))) |
54 | 74 | (hot-core (/ actual-width 2))) |
55 | 75 | (delete-char actual-width) |
56 | 76 | (insert (propertize (make-string actual-width fireplace-fill-char) |
57 | 77 | 'face `(:background ,"dark orange"))) |
58 | 78 | (when (> hot-core 1) |
59 | | - (gotoxy (+ x (/ hot-core 2)) y) |
| 79 | + (fireplace--gotoxy (+ x (/ hot-core 2)) y) |
60 | 80 | (delete-char hot-core) |
61 | 81 | (insert (propertize (make-string hot-core fireplace-fill-char) |
62 | 82 | 'face `(:background ,"orange red")))))) |
63 | 83 |
|
64 | | -(defun smoke (x height) |
65 | | - (gotoxy (if (>(random 3) 1) |
66 | | - (+ x (random (/ fp-bkgd-width 5))) |
67 | | - (max 0 (- x (random (/ fp-bkgd-width 5))))) |
68 | | - (+ height (random (- fp-bkgd-height height)))) |
| 84 | +(defun fireplace--smoke (x height) |
| 85 | + (fireplace--gotoxy (if (>(random 3) 1) |
| 86 | + (+ x (random (/ fireplace--bkgd-width 5))) |
| 87 | + (max 0 (- x (random (/ fireplace--bkgd-width 5))))) |
| 88 | + (+ height (random (- fireplace--bkgd-height height)))) |
69 | 89 | (delete-char 1) |
70 | 90 | (insert (propertize (make-string 1 fireplace-smoke-char) |
71 | 91 | 'face `(:foreground, "slate grey")))) |
72 | 92 |
|
73 | | -(defun flame (middle h) |
| 93 | +(defun fireplace--flame (middle h) |
74 | 94 | (setq cursor-type nil) |
75 | 95 | (let* ((width h) |
76 | 96 | (lower (truncate(* 0.2 h))) |
77 | 97 | (high (- h lower)) |
78 | 98 | x |
79 | 99 | line) |
80 | 100 | (dotimes (y lower) |
81 | | - (setq width (+ width y)) |
82 | | - (setq x (- middle (/ width 2))) |
| 101 | + (setq width (+ width y) |
| 102 | + x (- middle (/ width 2))) |
83 | 103 | (when (< x 0) |
84 | | - (setq width (+ width x)) |
85 | | - (setq x 0)) |
86 | | - (when (> (+ x width) fp-bkgd-width) |
87 | | - (setq width (- fp-bkgd-width x))) |
| 104 | + (setq width (+ width x) |
| 105 | + x 0)) |
| 106 | + (when (> (+ x width) fireplace--bkgd-width) |
| 107 | + (setq width (- fireplace--bkgd-width x))) |
88 | 108 | (draw-flame-stripe x y width)) |
89 | 109 | (dotimes (y high) |
90 | 110 | (setq line (+ lower y)) |
91 | 111 | (setq width (max 0 (- width 1 (random 3)))) |
92 | 112 | (setq x (- middle (/ width 2))) |
93 | 113 | (when (< x 0) |
94 | | - (setq width (+ width x)) |
95 | | - (setq x 0)) |
96 | | - (when (> (+ x width) fp-bkgd-width) |
97 | | - (setq width (- fp-bkgd-width x))) |
| 114 | + (setq width (+ width x) |
| 115 | + x 0)) |
| 116 | + (when (> (+ x width) fireplace--bkgd-width) |
| 117 | + (setq width (- fireplace--bkgd-width x))) |
98 | 118 | (draw-flame-stripe x line width) |
99 | | - (when fireplace-smoke-on (smoke x h))))) |
| 119 | + (when fireplace-smoke-on (fireplace--smoke x h))))) |
100 | 120 |
|
101 | 121 | (defun draw-fireplace (buffer-name flame-pos flame-width) |
102 | 122 | (with-current-buffer (get-buffer-create buffer-name) |
103 | 123 | (setq buffer-read-only nil) |
104 | | - (make-grid) |
| 124 | + (fireplace--make-grid) |
105 | 125 | (dolist (pos flame-pos) |
106 | | - (flame (round (* pos fp-bkgd-width)) |
| 126 | + (fireplace--flame (round (* pos fireplace--bkgd-width)) |
107 | 127 | (+ |
108 | 128 | (round (* (+ 0.2 (min pos (- 1 pos))) flame-width)) |
109 | 129 | (random 3)))) |
110 | 130 | (setq buffer-read-only t))) |
111 | 131 |
|
112 | 132 |
|
113 | | -;;Commands |
114 | | - |
| 133 | +;; Commands |
| 134 | +;;;###autoload |
115 | 135 | (defun fireplace (arg) |
| 136 | + "Turn on the fire like it's winter." |
116 | 137 | (interactive "P") |
117 | 138 | (with-current-buffer (get-buffer-create fireplace-buffer-name) |
118 | 139 | (setq cursor-type nil) |
119 | 140 | (buffer-disable-undo) |
120 | 141 | (switch-to-buffer fireplace-buffer-name) |
121 | | - (setq fp-bkgd-height (round (window-height (get-buffer-window fireplace-buffer-name)))) |
122 | | - (setq fp-bkgd-width (round (window-width (get-buffer-window fireplace-buffer-name)))) |
123 | | - (setq fp-flame-width (min fp-bkgd-height (round (/ fp-bkgd-width 2.5)))) |
124 | | - (make-grid) |
| 142 | + (setq fireplace--bkgd-height (round (window-height (get-buffer-window fireplace-buffer-name))) |
| 143 | + fireplace--bkgd-width (round (window-width (get-buffer-window fireplace-buffer-name))) |
| 144 | + fireplace--flame-width (min fireplace--bkgd-height (round (/ fireplace--bkgd-width 2.5)))) |
| 145 | + (fireplace--make-grid) |
125 | 146 | (fireplace-mode) |
126 | | - (setq fp-timer (run-with-timer 1 (- 1 fireplace-fury) |
127 | | - 'draw-fireplace fireplace-buffer-name fireplace-flame-pos fp-flame-width)))) |
| 147 | + (setq fireplace--timer (run-with-timer 1 (- 1 fireplace-fury) |
| 148 | + 'draw-fireplace fireplace-buffer-name fireplace-flame-pos fireplace--flame-width)))) |
128 | 149 |
|
129 | 150 | (defun fireplace-off () |
130 | 151 | "Put out the fire." |
131 | 152 | (interactive) |
132 | | - (when fp-timer |
133 | | - (cancel-timer fp-timer) |
| 153 | + (when fireplace--timer |
| 154 | + (cancel-timer fireplace--timer) |
134 | 155 | (kill-buffer fireplace-buffer-name))) |
135 | 156 |
|
136 | 157 | (defun fireplace-down () |
137 | 158 | (interactive) |
138 | 159 | "Push the fire further down" |
139 | | - (setq fp-bkgd-height (+ fp-bkgd-height 1))) |
| 160 | + (setq fireplace--bkgd-height (+ fireplace--bkgd-height 1))) |
140 | 161 |
|
141 | 162 |
|
142 | 163 | (defun fireplace-up () |
143 | 164 | (interactive) |
144 | 165 | "Move the fire further up" |
145 | | - (setq fp-bkgd-height (max 0 (- fp-bkgd-height 1)))) |
| 166 | + (setq fireplace--bkgd-height (max 0 (- fireplace--bkgd-height 1)))) |
146 | 167 |
|
147 | 168 | (defun fireplace-toggle-smoke () |
148 | 169 | (interactive) |
|
151 | 172 | (setq fireplace-smoke-on nil) |
152 | 173 | (setq fireplace-smoke-on t))) |
153 | 174 |
|
154 | | -(provide 'fireplace) |
155 | | -(provide 'fireplace-off) |
156 | | -(provide 'fireplace-down) |
157 | | - |
158 | 175 | ;;Key-bindings |
159 | 176 |
|
160 | | -(define-derived-mode fireplace-mode special-mode |
161 | | - "A cozy fireplace") |
162 | | - |
| 177 | +(define-derived-mode fireplace-mode special-mode "A cozy fireplace") |
163 | 178 |
|
164 | 179 | (define-key fireplace-mode-map (kbd "C-+") 'fireplace-down) |
165 | 180 | (define-key fireplace-mode-map (kbd "C--") 'fireplace-up) |
166 | | -(define-key fireplace-mode-map (kbd "C-s") 'fireplace-toggle-smoke) |
| 181 | +(define-key fireplace-mode-map (kbd "C-*") 'fireplace-toggle-smoke) |
167 | 182 |
|
| 183 | +(provide 'fireplace) |
168 | 184 | ;;; fireplace.el ends here |
0 commit comments