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