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