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