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