]> code.delx.au - gnu-emacs/blobdiff - lisp/play/animate.el
*** empty log message ***
[gnu-emacs] / lisp / play / animate.el
index 4d4a6e7a6485765a2d0f5e44b867ea29279b9cae..c7d659e0c990cd79950be0d687ad10b3871c9f4f 100644 (file)
@@ -1,6 +1,9 @@
 ;;; animate.el --- make text dance
 
-;; Copyright (C) 2001 Free Software Foundation, Inc.
+;; Copyright (C) 2001,2005 Free Software Foundation, Inc.
+
+;; Maintainer: Richard Stallman <rms@gnu.org>
+;; Keywords: games
 
 ;; This file is part of GNU Emacs.
 
 ;;; Place the character CHAR at position VPOS, HPOS in the current buffer.
 (defun animate-place-char (char vpos hpos)
   (goto-char (window-start))
-  (let ((next-line-add-newlines t))
+  (let (abbrev-mode)
     (dotimes (i vpos)
-      (next-line 1)))
+      (end-of-line)
+      (if (= (forward-line 1) 1)
+         (insert "\n"))))
   (beginning-of-line)
   (move-to-column (floor hpos) t)
   (unless (eolp) (delete-char 1))
@@ -101,7 +106,7 @@ in the current window."
                             (or hpos
                                 ;; HPOS unspecified, so compute
                                 ;; it so as to center the string.
-                                (/ (- (window-width) (length string)) 2)))))
+                                (max 0 (/ (- (window-width) (length string)) 2))))))
     (dotimes (i animate-n-steps)
       ;; Bind buffer-undo-list so it will be unchanged when we are done.
       ;; (We're going to undo all our changes anyway.)
@@ -130,11 +135,31 @@ in the current window."
     (undo-boundary)))
 
 ;;;###autoload
-(defun animate-birthday-present ()
-  "Display Sarah's birthday present."
-  (interactive)
+(defun animate-sequence (list-of-strings space)
+  "Display strings from LIST-OF-STRING with animation in a new buffer.
+Strings will be separated from each other by SPACE lines."
+  (let ((vpos (/ (- (window-height)
+                   1 ;; For the mode-line
+                   (* (1- (length list-of-strings)) space)
+                   (length list-of-strings))
+                2)))
+    (switch-to-buffer (get-buffer-create "*Animation*"))
+    (erase-buffer)
+    (sit-for 0)
+    (setq indent-tabs-mode nil)
+    (while list-of-strings
+      (animate-string (car list-of-strings) vpos)
+      (setq vpos (+ vpos space 1))
+      (setq list-of-strings (cdr list-of-strings)))))
+
+;;;###autoload
+(defun animate-birthday-present (&optional name)
+  "Display one's birthday present in a new buffer.
+You can specify the one's name by NAME; the default value is \"Sarah\"."
+  (interactive (list (read-string "Name (default \"Sarah\"): "
+                                 nil nil "Sarah")))
   ;; Make a suitable buffer to display the birthday present in.
-  (switch-to-buffer (get-buffer-create "Sarah"))
+  (switch-to-buffer (get-buffer-create (format "*%s*" name)))
   (erase-buffer)
   ;; Display the empty buffer.
   (sit-for 0)
@@ -143,7 +168,7 @@ in the current window."
   (setq indent-tabs-mode nil)
 
   (animate-string "Happy Birthday," 6)
-  (animate-string "Sarah" 7)
+  (animate-string (format "%s" name) 7)
 
   (sit-for 1)
 
@@ -163,5 +188,5 @@ in the current window."
   (animate-string "my sunshine" 18 34)
   (animate-string "to stay!" 19 34))
 
+;;; arch-tag: 275289a3-6ac4-41da-b527-a1147045392f
 ;;; animate.el ends here
-