Commit | Line | Data |
---|---|---|
abb2db1c GM |
1 | ;;; zone.el --- idle display hacks |
2 | ||
5fd6d89f TTN |
3 | ;; Copyright (C) 2000, 2001, 2002, 2003, 2004, |
4 | ;; 2005 Free Software Foundation, Inc. | |
abb2db1c | 5 | |
60370d40 PJ |
6 | ;; Author: Victor Zandy <zandy@cs.wisc.edu> |
7 | ;; Maintainer: Thien-Thi Nguyen <ttn@gnu.org> | |
8 | ;; Keywords: games | |
9 | ;; Created: June 6, 1998 | |
abb2db1c GM |
10 | |
11 | ;; This file is part of GNU Emacs. | |
12 | ||
13 | ;; GNU Emacs is free software; you can redistribute it and/or modify | |
14 | ;; it under the terms of the GNU General Public License as published by | |
15 | ;; the Free Software Foundation; either version 2, or (at your option) | |
16 | ;; any later version. | |
17 | ||
18 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
19 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21 | ;; GNU General Public License for more details. | |
22 | ||
23 | ;; You should have received a copy of the GNU General Public License | |
24 | ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
3a35cf56 LK |
25 | ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
26 | ;; Boston, MA 02110-1301, USA. | |
abb2db1c GM |
27 | |
28 | ;;; Commentary: | |
29 | ||
30 | ;; Don't zone out in front of Emacs! Try M-x zone. | |
31 | ;; If it eventually irritates you, try M-x zone-leave-me-alone. | |
32 | ||
33 | ;; Bored by the zone pyrotechnics? Write your own! Add it to | |
df9d055e | 34 | ;; `zone-programs'. See `zone-call' for higher-ordered zoning. |
abb2db1c GM |
35 | |
36 | ;; WARNING: Not appropriate for Emacs sessions over modems or | |
3cc2b29c | 37 | ;; computers as slow as mine. |
abb2db1c | 38 | |
3cc2b29c TTN |
39 | ;; THANKS: Christopher Mayer, Scott Flinchbaugh, |
40 | ;; Rachel Kalmar, Max Froumentin, Juri Linkov, | |
41 | ;; Luigi Panzeri, John Paul Wallington. | |
abb2db1c GM |
42 | |
43 | ;;; Code: | |
44 | ||
45 | (require 'timer) | |
46 | (require 'tabify) | |
47 | (eval-when-compile (require 'cl)) | |
48 | ||
216640c5 RS |
49 | (defvar zone-timer nil |
50 | "The timer we use to decide when to zone out, or nil if none.") | |
51 | ||
df9d055e TTN |
52 | (defvar zone-timeout nil |
53 | "*Seconds to timeout the zoning. | |
54 | If nil, don't interrupt for about 1^26 seconds.") | |
55 | ||
abb2db1c GM |
56 | ;; Vector of functions that zone out. `zone' will execute one of |
57 | ;; these functions, randomly chosen. The chosen function is invoked | |
58 | ;; in the *zone* buffer, which contains the text of the selected | |
59 | ;; window. If the function loops, it *must* periodically check and | |
60 | ;; halt if `input-pending-p' is t (because quitting is disabled when | |
61 | ;; Emacs idle timers are run). | |
62 | (defvar zone-programs [ | |
63 | zone-pgm-jitter | |
64 | zone-pgm-putz-with-case | |
65 | zone-pgm-dissolve | |
df9d055e | 66 | ;; zone-pgm-explode |
abb2db1c GM |
67 | zone-pgm-whack-chars |
68 | zone-pgm-rotate | |
69 | zone-pgm-rotate-LR-lockstep | |
70 | zone-pgm-rotate-RL-lockstep | |
71 | zone-pgm-rotate-LR-variable | |
72 | zone-pgm-rotate-RL-variable | |
73 | zone-pgm-drip | |
74 | zone-pgm-drip-fretfully | |
75 | zone-pgm-five-oclock-swan-dive | |
76 | zone-pgm-martini-swan-dive | |
77 | zone-pgm-paragraph-spaz | |
78 | zone-pgm-stress | |
df9d055e | 79 | zone-pgm-stress-destress |
0ccb50fc | 80 | zone-pgm-random-life |
abb2db1c GM |
81 | ]) |
82 | ||
83 | (defmacro zone-orig (&rest body) | |
84 | `(with-current-buffer (get 'zone 'orig-buffer) | |
85 | ,@body)) | |
86 | ||
df9d055e TTN |
87 | (defmacro zone-hiding-modeline (&rest body) |
88 | `(let (bg mode-line-fg mode-line-bg mode-line-box) | |
89 | (unwind-protect | |
90 | (progn | |
91 | (when (and (= 0 (get 'zone 'modeline-hidden-level)) | |
92 | (display-color-p)) | |
93 | (setq bg (face-background 'default) | |
94 | mode-line-box (face-attribute 'mode-line :box) | |
95 | mode-line-fg (face-attribute 'mode-line :foreground) | |
96 | mode-line-bg (face-attribute 'mode-line :background)) | |
97 | (set-face-attribute 'mode-line nil | |
98 | :foreground bg | |
99 | :background bg | |
100 | :box nil)) | |
101 | (put 'zone 'modeline-hidden-level | |
102 | (1+ (get 'zone 'modeline-hidden-level))) | |
103 | ,@body) | |
104 | (put 'zone 'modeline-hidden-level | |
105 | (1- (get 'zone 'modeline-hidden-level))) | |
106 | (when (and (> 1 (get 'zone 'modeline-hidden-level)) | |
107 | mode-line-fg) | |
108 | (set-face-attribute 'mode-line nil | |
109 | :foreground mode-line-fg | |
110 | :background mode-line-bg | |
111 | :box mode-line-box))))) | |
112 | ||
113 | (defun zone-call (program &optional timeout) | |
114 | "Call PROGRAM in a zoned way. | |
115 | If PROGRAM is a function, call it, interrupting after the amount | |
116 | of time in seconds specified by optional arg TIMEOUT, or `zone-timeout' | |
117 | if unspecified, q.v. | |
118 | PROGRAM can also be a list of elements, which are interpreted like so: | |
119 | If the element is a function or a list of a function and a number, | |
120 | apply `zone-call' recursively." | |
121 | (cond ((functionp program) | |
122 | (with-timeout ((or timeout zone-timeout (ash 1 26))) | |
123 | (funcall program))) | |
124 | ((listp program) | |
125 | (mapcar (lambda (elem) | |
126 | (cond ((functionp elem) (zone-call elem)) | |
127 | ((and (listp elem) | |
128 | (functionp (car elem)) | |
129 | (numberp (cadr elem))) | |
130 | (apply 'zone-call elem)) | |
dc120317 | 131 | (t (error "bad `zone-call' elem: %S" elem)))) |
df9d055e TTN |
132 | program)))) |
133 | ||
abb2db1c GM |
134 | ;;;###autoload |
135 | (defun zone () | |
136 | "Zone out, completely." | |
137 | (interactive) | |
2e78d4ab | 138 | (let ((f (selected-frame)) |
abb2db1c | 139 | (outbuf (get-buffer-create "*zone*")) |
930baf47 TTN |
140 | (text (buffer-substring (window-start) (window-end))) |
141 | (wp (1+ (- (window-point (selected-window)) | |
142 | (window-start))))) | |
abb2db1c | 143 | (put 'zone 'orig-buffer (current-buffer)) |
df9d055e | 144 | (put 'zone 'modeline-hidden-level 0) |
3ef80852 | 145 | (switch-to-buffer outbuf) |
abb2db1c GM |
146 | (setq mode-name "Zone") |
147 | (erase-buffer) | |
3ef80852 TTN |
148 | (setq buffer-undo-list t |
149 | truncate-lines t | |
e3fa1c11 TTN |
150 | tab-width (zone-orig tab-width) |
151 | line-spacing (zone-orig line-spacing)) | |
abb2db1c | 152 | (insert text) |
abb2db1c GM |
153 | (untabify (point-min) (point-max)) |
154 | (set-window-start (selected-window) (point-min)) | |
155 | (set-window-point (selected-window) wp) | |
156 | (sit-for 0 500) | |
157 | (let ((pgm (elt zone-programs (random (length zone-programs)))) | |
8b000fc3 TTN |
158 | (ct (and f (frame-parameter f 'cursor-type))) |
159 | (restore (list '(kill-buffer outbuf)))) | |
160 | (when ct | |
161 | (modify-frame-parameters f '((cursor-type . (bar . 0)))) | |
162 | (setq restore (cons '(modify-frame-parameters | |
163 | f (list (cons 'cursor-type ct))) | |
164 | restore))) | |
165 | ;; Make `restore' a self-disabling one-shot thunk. | |
166 | (setq restore `(lambda () ,@restore (setq restore nil))) | |
abb2db1c | 167 | (condition-case nil |
930baf47 | 168 | (progn |
abb2db1c | 169 | (message "Zoning... (%s)" pgm) |
930baf47 TTN |
170 | (garbage-collect) |
171 | ;; If some input is pending, zone says "sorry", which | |
172 | ;; isn't nice; this might happen e.g. when they invoke the | |
173 | ;; game by clicking the menu bar. So discard any pending | |
174 | ;; input before zoning out. | |
175 | (if (input-pending-p) | |
176 | (discard-input)) | |
df9d055e | 177 | (zone-call pgm) |
930baf47 TTN |
178 | (message "Zoning...sorry")) |
179 | (error | |
8b000fc3 | 180 | (funcall restore) |
930baf47 | 181 | (while (not (input-pending-p)) |
8c307e0f | 182 | (message "We were zoning when we wrote %s..." pgm) |
930baf47 TTN |
183 | (sit-for 3) |
184 | (message "...here's hoping we didn't hose your buffer!") | |
185 | (sit-for 3))) | |
8b000fc3 TTN |
186 | (quit |
187 | (funcall restore) | |
188 | (ding) | |
189 | (message "Zoning...sorry"))) | |
190 | (when restore (funcall restore))))) | |
abb2db1c GM |
191 | |
192 | ;;;; Zone when idle, or not. | |
193 | ||
abb2db1c GM |
194 | (defun zone-when-idle (secs) |
195 | "Zone out when Emacs has been idle for SECS seconds." | |
196 | (interactive "nHow long before I start zoning (seconds): ") | |
216640c5 RS |
197 | (if (timerp zone-timer) |
198 | (cancel-timer zone-timer)) | |
199 | (setq zone-timer nil) | |
abb2db1c | 200 | (or (<= secs 0) |
216640c5 | 201 | (setq zone-timer (run-with-idle-timer secs t 'zone)))) |
abb2db1c GM |
202 | |
203 | (defun zone-leave-me-alone () | |
204 | "Don't zone out when Emacs is idle." | |
205 | (interactive) | |
216640c5 RS |
206 | (if (timerp zone-timer) |
207 | (cancel-timer zone-timer)) | |
208 | (setq zone-timer nil) | |
abb2db1c GM |
209 | (message "I won't zone out any more")) |
210 | ||
211 | ||
3ef80852 | 212 | ;;;; jittering |
abb2db1c GM |
213 | |
214 | (defun zone-shift-up () | |
215 | (let* ((b (point)) | |
3ef80852 | 216 | (e (progn (forward-line 1) (point))) |
df9d055e | 217 | (s (buffer-substring b e))) |
abb2db1c GM |
218 | (delete-region b e) |
219 | (goto-char (point-max)) | |
220 | (insert s))) | |
221 | ||
222 | (defun zone-shift-down () | |
223 | (goto-char (point-max)) | |
abb2db1c | 224 | (let* ((b (point)) |
3ef80852 | 225 | (e (progn (forward-line -1) (point))) |
df9d055e | 226 | (s (buffer-substring b e))) |
abb2db1c GM |
227 | (delete-region b e) |
228 | (goto-char (point-min)) | |
229 | (insert s))) | |
230 | ||
231 | (defun zone-shift-left () | |
3ef80852 TTN |
232 | (let (s) |
233 | (while (not (eobp)) | |
234 | (unless (eolp) | |
235 | (setq s (buffer-substring (point) (1+ (point)))) | |
236 | (delete-char 1) | |
237 | (end-of-line) | |
238 | (insert s)) | |
239 | (forward-char 1)))) | |
abb2db1c GM |
240 | |
241 | (defun zone-shift-right () | |
3ef80852 TTN |
242 | (goto-char (point-max)) |
243 | (end-of-line) | |
244 | (let (s) | |
245 | (while (not (bobp)) | |
246 | (unless (bolp) | |
247 | (setq s (buffer-substring (1- (point)) (point))) | |
248 | (delete-char -1) | |
249 | (beginning-of-line) | |
250 | (insert s)) | |
251 | (end-of-line 0)))) | |
abb2db1c GM |
252 | |
253 | (defun zone-pgm-jitter () | |
254 | (let ((ops [ | |
abb2db1c GM |
255 | zone-shift-left |
256 | zone-shift-right | |
257 | zone-shift-down | |
abb2db1c GM |
258 | zone-shift-up |
259 | ])) | |
260 | (goto-char (point-min)) | |
261 | (while (not (input-pending-p)) | |
262 | (funcall (elt ops (random (length ops)))) | |
263 | (goto-char (point-min)) | |
264 | (sit-for 0 10)))) | |
265 | ||
266 | ||
3ef80852 | 267 | ;;;; whacking chars |
abb2db1c | 268 | |
abb2db1c | 269 | (defun zone-pgm-whack-chars () |
930baf47 | 270 | (let ((tbl (copy-sequence (get 'zone-pgm-whack-chars 'wc-tbl)))) |
abb2db1c GM |
271 | (while (not (input-pending-p)) |
272 | (let ((i 48)) | |
df9d055e TTN |
273 | (while (< i 122) |
274 | (aset tbl i (+ 48 (random (- 123 48)))) | |
275 | (setq i (1+ i))) | |
276 | (translate-region (point-min) (point-max) tbl) | |
277 | (sit-for 0 2))))) | |
930baf47 TTN |
278 | |
279 | (put 'zone-pgm-whack-chars 'wc-tbl | |
df9d055e | 280 | (let ((tbl (make-string 128 ?x)) |
930baf47 TTN |
281 | (i 0)) |
282 | (while (< i 128) | |
283 | (aset tbl i i) | |
284 | (setq i (1+ i))) | |
285 | tbl)) | |
abb2db1c | 286 | |
3ef80852 | 287 | ;;;; dissolving |
abb2db1c GM |
288 | |
289 | (defun zone-remove-text () | |
290 | (let ((working t)) | |
291 | (while working | |
292 | (setq working nil) | |
293 | (save-excursion | |
df9d055e TTN |
294 | (goto-char (point-min)) |
295 | (while (not (eobp)) | |
296 | (if (looking-at "[^(){}\n\t ]") | |
297 | (let ((n (random 5))) | |
298 | (if (not (= n 0)) | |
299 | (progn | |
300 | (setq working t) | |
301 | (forward-char 1)) | |
302 | (delete-char 1) | |
303 | (insert " "))) | |
304 | (forward-char 1)))) | |
abb2db1c GM |
305 | (sit-for 0 2)))) |
306 | ||
307 | (defun zone-pgm-dissolve () | |
308 | (zone-remove-text) | |
309 | (zone-pgm-jitter)) | |
310 | ||
311 | ||
3ef80852 | 312 | ;;;; exploding |
abb2db1c GM |
313 | |
314 | (defun zone-exploding-remove () | |
315 | (let ((i 0)) | |
3ef80852 | 316 | (while (< i 5) |
abb2db1c | 317 | (save-excursion |
df9d055e TTN |
318 | (goto-char (point-min)) |
319 | (while (not (eobp)) | |
320 | (if (looking-at "[^*\n\t ]") | |
321 | (let ((n (random 5))) | |
322 | (if (not (= n 0)) | |
323 | (forward-char 1)) | |
324 | (insert " "))) | |
325 | (forward-char 1))) | |
abb2db1c GM |
326 | (setq i (1+ i)) |
327 | (sit-for 0 2))) | |
328 | (zone-pgm-jitter)) | |
329 | ||
330 | (defun zone-pgm-explode () | |
331 | (zone-exploding-remove) | |
332 | (zone-pgm-jitter)) | |
333 | ||
334 | ||
3ef80852 | 335 | ;;;; putzing w/ case |
abb2db1c GM |
336 | |
337 | ;; Faster than `zone-pgm-putz-with-case', but not as good: all | |
338 | ;; instances of the same letter have the same case, which produces a | |
339 | ;; less interesting effect than you might imagine. | |
340 | (defun zone-pgm-2nd-putz-with-case () | |
341 | (let ((tbl (make-string 128 ?x)) | |
df9d055e | 342 | (i 0)) |
abb2db1c GM |
343 | (while (< i 128) |
344 | (aset tbl i i) | |
345 | (setq i (1+ i))) | |
346 | (while (not (input-pending-p)) | |
347 | (setq i ?a) | |
348 | (while (<= i ?z) | |
df9d055e TTN |
349 | (aset tbl i |
350 | (if (zerop (random 5)) | |
351 | (upcase i) | |
352 | (downcase i))) | |
353 | (setq i (+ i (1+ (random 5))))) | |
abb2db1c GM |
354 | (setq i ?A) |
355 | (while (<= i ?z) | |
df9d055e TTN |
356 | (aset tbl i |
357 | (if (zerop (random 5)) | |
358 | (downcase i) | |
359 | (upcase i))) | |
360 | (setq i (+ i (1+ (random 5))))) | |
abb2db1c GM |
361 | (translate-region (point-min) (point-max) tbl) |
362 | (sit-for 0 2)))) | |
363 | ||
364 | (defun zone-pgm-putz-with-case () | |
365 | (goto-char (point-min)) | |
366 | (while (not (input-pending-p)) | |
367 | (let ((np (+ 2 (random 5))) | |
df9d055e | 368 | (pm (point-max))) |
abb2db1c | 369 | (while (< np pm) |
df9d055e | 370 | (goto-char np) |
abb2db1c GM |
371 | (let ((prec (preceding-char)) |
372 | (props (text-properties-at (1- (point))))) | |
373 | (insert (if (zerop (random 2)) | |
374 | (upcase prec) | |
375 | (downcase prec))) | |
376 | (set-text-properties (1- (point)) (point) props)) | |
df9d055e TTN |
377 | (backward-char 2) |
378 | (delete-char 1) | |
379 | (setq np (+ np (1+ (random 5)))))) | |
abb2db1c GM |
380 | (goto-char (point-min)) |
381 | (sit-for 0 2))) | |
382 | ||
383 | ||
3ef80852 | 384 | ;;;; rotating |
abb2db1c GM |
385 | |
386 | (defun zone-line-specs () | |
387 | (let (ret) | |
388 | (save-excursion | |
389 | (goto-char (window-start)) | |
390 | (while (< (point) (window-end)) | |
df9d055e TTN |
391 | (when (looking-at "[\t ]*\\([^\n]+\\)") |
392 | (setq ret (cons (cons (match-beginning 1) (match-end 1)) ret))) | |
393 | (forward-line 1))) | |
abb2db1c GM |
394 | ret)) |
395 | ||
396 | (defun zone-pgm-rotate (&optional random-style) | |
397 | (let* ((specs (apply | |
930baf47 | 398 | 'vector |
abb2db1c GM |
399 | (let (res) |
400 | (mapcar (lambda (ent) | |
401 | (let* ((beg (car ent)) | |
402 | (end (cdr ent)) | |
403 | (amt (if random-style | |
404 | (funcall random-style) | |
405 | (- (random 7) 3)))) | |
406 | (when (< (- end (abs amt)) beg) | |
407 | (setq amt (random (- end beg)))) | |
408 | (unless (= 0 amt) | |
409 | (setq res | |
410 | (cons | |
411 | (vector amt beg (- end (abs amt))) | |
412 | res))))) | |
413 | (zone-line-specs)) | |
414 | res))) | |
930baf47 TTN |
415 | (n (length specs)) |
416 | amt aamt cut paste txt i ent) | |
abb2db1c GM |
417 | (while (not (input-pending-p)) |
418 | (setq i 0) | |
419 | (while (< i n) | |
930baf47 TTN |
420 | (setq ent (aref specs i)) |
421 | (setq amt (aref ent 0) aamt (abs amt)) | |
422 | (if (> 0 amt) | |
423 | (setq cut 1 paste 2) | |
424 | (setq cut 2 paste 1)) | |
425 | (goto-char (aref ent cut)) | |
426 | (setq txt (buffer-substring (point) (+ (point) aamt))) | |
427 | (delete-char aamt) | |
428 | (goto-char (aref ent paste)) | |
429 | (insert txt) | |
430 | (setq i (1+ i))) | |
abb2db1c GM |
431 | (sit-for 0.04)))) |
432 | ||
433 | (defun zone-pgm-rotate-LR-lockstep () | |
434 | (zone-pgm-rotate (lambda () 1))) | |
435 | ||
436 | (defun zone-pgm-rotate-RL-lockstep () | |
437 | (zone-pgm-rotate (lambda () -1))) | |
438 | ||
439 | (defun zone-pgm-rotate-LR-variable () | |
440 | (zone-pgm-rotate (lambda () (1+ (random 3))))) | |
441 | ||
442 | (defun zone-pgm-rotate-RL-variable () | |
443 | (zone-pgm-rotate (lambda () (1- (- (random 3)))))) | |
444 | ||
445 | ||
3ef80852 | 446 | ;;;; dripping |
abb2db1c | 447 | |
3ef80852 | 448 | (defsubst zone-cpos (pos) |
abb2db1c GM |
449 | (buffer-substring pos (1+ pos))) |
450 | ||
e3fa1c11 TTN |
451 | (defsubst zone-replace-char (count del-count char-as-string new-value) |
452 | (delete-char (or del-count (- count))) | |
3ef80852 | 453 | (aset char-as-string 0 new-value) |
e3fa1c11 | 454 | (dotimes (i count) (insert char-as-string))) |
3ef80852 TTN |
455 | |
456 | (defsubst zone-park/sit-for (pos seconds) | |
457 | (let ((p (point))) | |
458 | (goto-char pos) | |
459 | (prog1 (sit-for seconds) | |
460 | (goto-char p)))) | |
461 | ||
462 | (defun zone-fret (wbeg pos) | |
abb2db1c GM |
463 | (let* ((case-fold-search nil) |
464 | (c-string (zone-cpos pos)) | |
e3fa1c11 | 465 | (cw-ceil (ceiling (char-width (aref c-string 0)))) |
abb2db1c GM |
466 | (hmm (cond |
467 | ((string-match "[a-z]" c-string) (upcase c-string)) | |
468 | ((string-match "[A-Z]" c-string) (downcase c-string)) | |
e3fa1c11 | 469 | (t (propertize " " 'display `(space :width ,cw-ceil)))))) |
abb2db1c GM |
470 | (do ((i 0 (1+ i)) |
471 | (wait 0.5 (* wait 0.8))) | |
472 | ((= i 20)) | |
473 | (goto-char pos) | |
474 | (delete-char 1) | |
475 | (insert (if (= 0 (% i 2)) hmm c-string)) | |
3ef80852 | 476 | (zone-park/sit-for wbeg wait)) |
abb2db1c GM |
477 | (delete-char -1) (insert c-string))) |
478 | ||
0ccb50fc | 479 | (defun zone-fill-out-screen (width height) |
3ef80852 TTN |
480 | (let ((start (window-start)) |
481 | (line (make-string width 32))) | |
482 | (goto-char start) | |
0ccb50fc | 483 | ;; fill out rectangular ws block |
3ef80852 TTN |
484 | (while (progn (end-of-line) |
485 | (let ((cc (current-column))) | |
486 | (if (< cc width) | |
487 | (insert (substring line cc)) | |
488 | (delete-char (- width cc))) | |
489 | (cond ((eobp) (insert "\n") nil) | |
490 | (t (forward-char 1) t))))) | |
0ccb50fc TTN |
491 | ;; pad ws past bottom of screen |
492 | (let ((nl (- height (count-lines (point-min) (point))))) | |
493 | (when (> nl 0) | |
3ef80852 TTN |
494 | (setq line (concat line "\n")) |
495 | (do ((i 0 (1+ i))) | |
496 | ((= i nl)) | |
497 | (insert line)))) | |
498 | (goto-char start) | |
499 | (recenter 0) | |
500 | (sit-for 0))) | |
501 | ||
e3fa1c11 TTN |
502 | (defun zone-fall-through-ws (c wbeg wend) |
503 | (let* ((cw-ceil (ceiling (char-width (aref c 0)))) | |
504 | (spaces (make-string cw-ceil 32)) | |
505 | (col (current-column)) | |
506 | (wait 0.15) | |
507 | newpos fall-p) | |
508 | (while (when (save-excursion | |
509 | (next-line 1) | |
510 | (and (= col (current-column)) | |
511 | (setq newpos (point)) | |
512 | (string= spaces (buffer-substring-no-properties | |
513 | newpos (+ newpos cw-ceil))) | |
514 | (setq newpos (+ newpos (1- cw-ceil))))) | |
3ef80852 TTN |
515 | (setq fall-p t) |
516 | (delete-char 1) | |
e3fa1c11 TTN |
517 | (insert spaces) |
518 | (goto-char newpos) | |
3ef80852 | 519 | (when (< (point) wend) |
e3fa1c11 | 520 | (delete-char cw-ceil) |
3ef80852 TTN |
521 | (insert c) |
522 | (forward-char -1) | |
523 | (zone-park/sit-for wbeg (setq wait (* wait 0.8)))))) | |
abb2db1c GM |
524 | fall-p)) |
525 | ||
526 | (defun zone-pgm-drip (&optional fret-p pancake-p) | |
527 | (let* ((ww (1- (window-width))) | |
528 | (wh (window-height)) | |
529 | (mc 0) ; miss count | |
530 | (total (* ww wh)) | |
3ef80852 TTN |
531 | (fall-p nil) |
532 | wbeg wend c) | |
0ccb50fc | 533 | (zone-fill-out-screen ww wh) |
3ef80852 TTN |
534 | (setq wbeg (window-start) |
535 | wend (window-end)) | |
df9d055e | 536 | (catch 'done |
abb2db1c | 537 | (while (not (input-pending-p)) |
e3fa1c11 | 538 | (setq mc 0 wend (window-end)) |
3ef80852 TTN |
539 | ;; select non-ws character, but don't miss too much |
540 | (goto-char (+ wbeg (random (- wend wbeg)))) | |
541 | (while (looking-at "[ \n\f]") | |
542 | (if (= total (setq mc (1+ mc))) | |
543 | (throw 'done 'sel) | |
544 | (goto-char (+ wbeg (random (- wend wbeg)))))) | |
545 | ;; character animation sequence | |
546 | (let ((p (point))) | |
547 | (when fret-p (zone-fret wbeg p)) | |
548 | (goto-char p) | |
549 | (setq c (zone-cpos p) | |
e3fa1c11 | 550 | fall-p (zone-fall-through-ws c wbeg wend))) |
abb2db1c GM |
551 | ;; assuming current-column has not changed... |
552 | (when (and pancake-p | |
553 | fall-p | |
554 | (< (count-lines (point-min) (point)) | |
555 | wh)) | |
e3fa1c11 TTN |
556 | (let ((cw (ceiling (char-width (aref c 0))))) |
557 | (zone-replace-char cw 1 c ?@) (zone-park/sit-for wbeg 0.137) | |
558 | (zone-replace-char cw nil c ?*) (zone-park/sit-for wbeg 0.137) | |
559 | (zone-replace-char cw nil c ?_))))))) | |
abb2db1c GM |
560 | |
561 | (defun zone-pgm-drip-fretfully () | |
562 | (zone-pgm-drip t)) | |
563 | ||
564 | (defun zone-pgm-five-oclock-swan-dive () | |
565 | (zone-pgm-drip nil t)) | |
566 | ||
567 | (defun zone-pgm-martini-swan-dive () | |
568 | (zone-pgm-drip t t)) | |
569 | ||
570 | ||
3ef80852 | 571 | ;;;; paragraph spazzing (for textish modes) |
abb2db1c GM |
572 | |
573 | (defun zone-pgm-paragraph-spaz () | |
0ccb50fc TTN |
574 | (if (memq (zone-orig major-mode) |
575 | ;; there should be a better way to distinguish textish modes | |
576 | '(text-mode texinfo-mode fundamental-mode)) | |
abb2db1c GM |
577 | (let ((fill-column fill-column) |
578 | (fc-min fill-column) | |
579 | (fc-max fill-column) | |
580 | (max-fc (1- (frame-width)))) | |
581 | (while (sit-for 0.1) | |
582 | (fill-paragraph 1) | |
583 | (setq fill-column (+ fill-column (- (random 5) 2))) | |
584 | (when (< fill-column fc-min) | |
585 | (setq fc-min fill-column)) | |
586 | (when (> fill-column max-fc) | |
587 | (setq fill-column max-fc)) | |
588 | (when (> fill-column fc-max) | |
589 | (setq fc-max fill-column)))) | |
590 | (message "Zoning... (zone-pgm-rotate)") | |
591 | (zone-pgm-rotate))) | |
592 | ||
593 | ||
0ccb50fc | 594 | ;;;; stressing and destressing |
abb2db1c GM |
595 | |
596 | (defun zone-pgm-stress () | |
597 | (goto-char (point-min)) | |
df9d055e | 598 | (let (lines) |
abb2db1c GM |
599 | (while (< (point) (point-max)) |
600 | (let ((p (point))) | |
601 | (forward-line 1) | |
602 | (setq lines (cons (buffer-substring p (point)) lines)))) | |
603 | (sit-for 5) | |
df9d055e TTN |
604 | (zone-hiding-modeline |
605 | (let ((msg "Zoning... (zone-pgm-stress)")) | |
606 | (while (not (string= msg "")) | |
607 | (message (setq msg (substring msg 1))) | |
608 | (sit-for 0.05))) | |
609 | (while (not (input-pending-p)) | |
610 | (when (< 50 (random 100)) | |
611 | (goto-char (point-max)) | |
612 | (forward-line -1) | |
613 | (let ((kill-whole-line t)) | |
614 | (kill-line)) | |
615 | (goto-char (point-min)) | |
616 | (insert (nth (random (length lines)) lines))) | |
617 | (message (concat (make-string (random (- (frame-width) 5)) ? ) "grrr")) | |
618 | (sit-for 0.1))))) | |
619 | ||
df9d055e TTN |
620 | (defun zone-pgm-stress-destress () |
621 | (zone-call 'zone-pgm-stress 25) | |
622 | (zone-hiding-modeline | |
623 | (sit-for 3) | |
624 | (erase-buffer) | |
625 | (sit-for 3) | |
f706036b | 626 | (insert-buffer-substring "*Messages*") |
df9d055e TTN |
627 | (message "") |
628 | (goto-char (point-max)) | |
629 | (recenter -1) | |
630 | (sit-for 3) | |
631 | (delete-region (point-min) (window-start)) | |
632 | (message "hey why stress out anyway?") | |
633 | (zone-call '((zone-pgm-rotate 30) | |
634 | (zone-pgm-whack-chars 10) | |
635 | zone-pgm-drip)))) | |
636 | ||
637 | ||
0ccb50fc TTN |
638 | ;;;; the lyfe so short the craft so long to lerne --chaucer |
639 | ||
640 | (defvar zone-pgm-random-life-wait nil | |
641 | "*Seconds to wait between successive `life' generations. | |
642 | If nil, `zone-pgm-random-life' chooses a value from 0-3 (inclusive).") | |
643 | ||
644 | (defun zone-pgm-random-life () | |
645 | (require 'life) | |
646 | (zone-fill-out-screen (1- (window-width)) (1- (window-height))) | |
647 | (let ((top (progn (goto-char (window-start)) (forward-line 7) (point))) | |
648 | (bot (progn (goto-char (window-end)) (forward-line -7) (point))) | |
649 | (rtc (- (frame-width) 11)) | |
650 | (min (window-start)) | |
651 | (max (1- (window-end))) | |
3ef80852 | 652 | s c col) |
0ccb50fc | 653 | (delete-region max (point-max)) |
3ef80852 TTN |
654 | (while (and (progn (goto-char min) (sit-for 0.05)) |
655 | (progn (goto-char (+ min (random max))) | |
0ccb50fc TTN |
656 | (or (progn (skip-chars-forward " @\n" max) |
657 | (not (= max (point)))) | |
658 | (unless (or (= 0 (skip-chars-backward " @\n" min)) | |
659 | (= min (point))) | |
660 | (forward-char -1) | |
661 | t)))) | |
3ef80852 TTN |
662 | (unless (or (eolp) (eobp)) |
663 | (setq s (zone-cpos (point)) | |
664 | c (aref s 0)) | |
665 | (zone-replace-char | |
e3fa1c11 | 666 | (char-width c) |
fc866a94 | 667 | 1 s (cond ((or (> top (point)) |
3ef80852 TTN |
668 | (< bot (point)) |
669 | (or (> 11 (setq col (current-column))) | |
670 | (< rtc col))) | |
671 | 32) | |
672 | ((and (<= ?a c) (>= ?z c)) (+ c (- ?A ?a))) | |
673 | ((and (<= ?A c) (>= ?Z c)) ?*) | |
674 | (t ?@))))) | |
0ccb50fc TTN |
675 | (sit-for 3) |
676 | (setq col nil) | |
677 | (goto-char bot) | |
678 | (while (< top (point)) | |
679 | (setq c (point)) | |
680 | (move-to-column 9) | |
681 | (setq col (cons (buffer-substring (point) c) col)) | |
682 | (end-of-line 0) | |
683 | (forward-char -10)) | |
3ef80852 | 684 | (let ((life-patterns (vector |
8b000fc3 | 685 | (if (and col (search-forward "@" max t)) |
3ef80852 TTN |
686 | (cons (make-string (length (car col)) 32) col) |
687 | (list (mapconcat 'identity | |
688 | (make-list (/ (- rtc 11) 15) | |
689 | (make-string 5 ?@)) | |
690 | (make-string 10 32))))))) | |
0ccb50fc TTN |
691 | (life (or zone-pgm-random-life-wait (random 4))) |
692 | (kill-buffer nil)))) | |
693 | ||
694 | ||
df9d055e | 695 | ;;;;;;;;;;;;;;; |
abb2db1c GM |
696 | (provide 'zone) |
697 | ||
ab5796a9 | 698 | ;;; arch-tag: 7092503d-74a9-4325-a55c-a026ede58cea |
abb2db1c | 699 | ;;; zone.el ends here |