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