zone.el 22 KB

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