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