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