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