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