home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 November / macformat-018.iso / Utility Spectacular / Text / Emacs-1.12d folder / lisp / life.elc < prev    next >
Encoding:
Text File  |  1993-11-09  |  5.1 KB  |  65 lines  |  [dELC/EMAC]

  1.  
  2. (provide (quote life))
  3.  
  4. (defconst life-patterns [("@@@" " @@" "@@@") ("@@@ @@@" "@@  @@ " "@@@ @@@") ("@@@ @@@" "@@   @@" "@@@ @@@") ("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@") ("@@@@@@@@@@") ("   @@@@@@@@@@       " "     @@@@@@@@@@     " "       @@@@@@@@@@   " "@@@@@@@@@@          " "@@@@@@@@@@          ") ("@" "@" "@" "@" "@" "@" "@" "@" "@" "@" "@" "@" "@" "@" "@") ("@               @" "@               @" "@               @" "@               @" "@               @" "@               @" "@               @" "@               @" "@               @" "@               @" "@               @" "@               @" "@               @" "@               @" "@               @") ("@@               " " @@              " "  @@             " "   @@            " "    @@           " "     @@          " "      @@         " "       @@        " "        @@       " "         @@      " "          @@     " "           @@    " "            @@   " "             @@  " "              @@ " "               @@") ("@@@@@@@@@" "@   @   @" "@ @@@@@ @" "@ @   @ @" "@@@   @@@" "@ @   @ @" "@ @@@@@ @" "@   @   @" "@@@@@@@@@")] "\
  5. Vector of rectangles containing some Life startup patterns.")
  6.  
  7. (require (progn (defmacro life-life-char nil 64) (defmacro life-death-char nil (1+ (life-life-char))) (defmacro life-birth-char nil 3) (defmacro life-void-char nil 32) (defmacro life-life-string nil (char-to-string (life-life-char))) (defmacro life-death-string nil (char-to-string (life-death-char))) (defmacro life-birth-string nil (char-to-string (life-birth-char))) (defmacro life-void-string nil (char-to-string (life-void-char))) (defmacro life-not-void-regexp nil (concat "[^" (life-void-string) "
  8. ]")) (defmacro goto-beginning-of-buffer nil (quote (goto-char 1))) (defmacro maxint nil (lsh (lsh (lognot 0) 1) -1)) (defmacro goto-end-of-buffer nil (quote (goto-char (maxint)))) (defmacro increment (variable) (list (quote setq) variable (list (quote 1+) variable))) (quote life)))
  9.  
  10. (defconst life-neighbor-deltas nil)
  11.  
  12. (defconst life-window-start nil)
  13.  
  14. (defconst life-current-generation nil)
  15.  
  16. (defconst life-generation-string nil)
  17.  
  18. (defun abs (n) (byte-code "¡WÉ [Ç á" [n 0] 2))
  19.  
  20. (defun life (&optional sleeptime) "\
  21. Run Conway's Life simulation.
  22. The starting pattern is randomly selected.  Prefix arg (optional first arg
  23. non-nil from a program) is the number of seconds to sleep between
  24. generations (this defaults to 1)." (interactive "p") (byte-code "√àÜ    ƒâà≈ àΔ!à¡Ö(¡« à» à… àΔ!)àÇá" [sleeptime t inhibit-quit nil 1 life-setup life-display-generation life-grim-reaper life-expand-plane-if-needed life-increment-generation] 8))
  25.  
  26. (fset (quote life-mode) (quote life))
  27.  
  28. (put (quote life-mode) (quote mode-class) (quote special))
  29.  
  30. (random t)
  31.  
  32. (defun life-setup nil (byte-code "√ÃÕŒ!¡\"àœ à– à√—“¡”‘’    ÷ S
  33. ◊â àÿp!àŸ à◊bà⁄€√¡#ÖF‹›¡¡#àÇ5à◊bàfi
  34. äfl à`)Z‡\"âàm?Ögjà· àÇYàfi‚ S„ed\"Z‡\"âà◊bà‰!àÂbà‰!à◊bàm?Ö¶fl à
  35. jàÊ
  36. !àÁ`fl à`\"à· àÇáàËed\"àÈ àÍ )á" [n t case-fold-search nil mode-name major-mode truncate-lines life-current-generation life-generation-string mode-line-buffer-identification fill-column life-window-start switch-to-buffer get-buffer-create "*Life*" erase-buffer kill-all-local-variables "Life" life-mode 0 "0" ("Life: generation " life-generation-string) window-width 1 buffer-flush-undo life-insert-random-pattern re-search-forward "[^ 
  37. ]" replace-match "@" / end-of-line 2 forward-line window-height count-lines newline 33554431 move-to-column delete-region untabify life-expand-plane-if-needed life-compute-neighbor-deltas] 26))
  38.  
  39. (defun life-compute-neighbor-deltas nil (byte-code "¬√    [    T[ƒ    \\[≈        Tƒ    \\&âá" [life-neighbor-deltas fill-column list -1 2 1] 10))
  40.  
  41. (defun life-insert-random-pattern nil (byte-code "¡¬√ƒ≈ !G\"\"!àΔcá" [life-patterns insert-rectangle elt % abs random 10] 8))
  42.  
  43. (defun life-increment-generation nil (byte-code "Tâà¬!âá" [life-current-generation life-generation-string int-to-string] 3))
  44.  
  45. (defun life-grim-reaper nil (byte-code "»¿!à…bà¿¿¿¿¿ À¿Δ#ÖèÃ`Sâà
  46. Öx
  47. @\\    fâà
  48. Õ=ÉBŒ        TÕ…Δ%Ço
  49. œWÉTŒ        T
  50.  
  51. TΔ%Ço
  52. –WÉeŒ        T
  53. –Δ%Ço
  54. —YÖo Tâà
  55. AâàÇ#à “>ÉÉ¿Ç㌠T—”Δ%àÇ-à‘Ã!?Öö’ àŒ…d–ÕΔ%àŒ…d…ÕΔ%àŒ…d÷ÕΔ%àŒ…dœ—Δ%àŒ…d”ÕΔ%á" [nil point char pivot living-neighbors list t life-neighbor-deltas store-match-data 1 search-forward "@" 0 32 subst-char-in-region 3 9 64 (2 3) 65 match-beginning life-extinct-quit 2] 18))
  56.  
  57. (defun life-expand-plane-if-needed nil (byte-code "√ƒçà≈bàΔ«»`…$¡#Ö.≈bà À\"àÃcà À\"àÃcà»
  58. ≈#âàÕbàŒ«œ`…$¡#ÖYÕbà À\"àÃcà À\"àÃcà»
  59. ≈#âá" [fill-column t life-window-start done (byte-code "¬bàm?ÖGg√=܃ àh√=Ö@¬bàm?Ö.≈càƒ à≈càΔ àÇà«\\â໬!à… à À¡\"àààÇá" [fill-column t 1 64 end-of-line 32 forward-char 2 scroll-left life-compute-neighbor-deltas throw done forward-line] 9) 1 search-forward "@" + 2 insert-char 32 10 33554431 search-backward -] 13))
  60.  
  61. (defun life-display-generation (sleeptime) (byte-code "bà¬√!àƒ    !á" [life-window-start sleeptime recenter 0 sit-for] 3))
  62.  
  63. (defun life-extinct-quit nil (byte-code "¡¬!à√ƒ¿\"á" [nil life-display-generation 0 signal life-extinct] 4))
  64.  
  65. (put (quote life-extinct) (quote error-conditions) (quote (life-extinct quit)))
  66.  
  67. (put (quote life-extinct) (quote error-message) "All life has perished")
  68.