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