2001-07-23 09:46:39 +00:00
|
|
|
;;; animate.el --- make text dance
|
|
|
|
|
2006-02-05 14:10:45 +00:00
|
|
|
;; Copyright (C) 2001, 2002, 2003, 2004, 2005,
|
2007-01-21 03:53:13 +00:00
|
|
|
;; 2006, 2007 Free Software Foundation, Inc.
|
2001-07-23 09:46:39 +00:00
|
|
|
|
2001-08-01 10:18:26 +00:00
|
|
|
;; Maintainer: Richard Stallman <rms@gnu.org>
|
|
|
|
;; Keywords: games
|
|
|
|
|
2001-07-23 09:46:39 +00:00
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
|
|
|
;; GNU Emacs is free software; you can redistribute it and/or modify
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
|
|
|
;; the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
;; any later version.
|
|
|
|
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
|
|
;; along with GNU Emacs; see the file COPYING. If not, write to the
|
2005-07-04 17:55:18 +00:00
|
|
|
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
;; Boston, MA 02110-1301, USA.
|
2001-07-23 09:46:39 +00:00
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
;; (animate-string STRING VPOS &optional HPOS)
|
|
|
|
;; makes the string STRING appear starting at VPOS, HPOS
|
|
|
|
;; by having each letter swoop into place from random starting position.
|
|
|
|
|
2001-08-06 21:29:16 +00:00
|
|
|
;; animate-birthday-present was the first application of this program.
|
|
|
|
|
2001-07-23 09:46:39 +00:00
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
;;; STRING is the string to be displayed,
|
|
|
|
;;; and DEST-X, DEST-Y say where on the screen
|
|
|
|
;;; it should end up.
|
|
|
|
|
|
|
|
;;; This function returns a list describing
|
|
|
|
;;; all the characters and the paths they should take.
|
|
|
|
;;; Each element has the form
|
|
|
|
;;; (CHAR START-Y START-X DEST-Y DEST-X).
|
|
|
|
|
|
|
|
;;; The start position of each character is chosen randomly.
|
|
|
|
;;; The destination is chosen to put it in the right place
|
|
|
|
;;; in the string when the whole string finally reaches its
|
|
|
|
;;; specified position.
|
|
|
|
|
|
|
|
(defun animate-initialize (string vpos hpos)
|
|
|
|
(let ((characters nil))
|
|
|
|
(dotimes (i (length string))
|
|
|
|
(setq characters
|
|
|
|
(cons (list (aref string i)
|
|
|
|
;; Random starting positions.
|
|
|
|
(random (window-height))
|
|
|
|
(random (1- (window-width)))
|
|
|
|
;; All the chars should end up
|
|
|
|
;; on the specified line.
|
|
|
|
vpos
|
|
|
|
;; The Ith character in the string
|
|
|
|
;; needs to end up I positions later.
|
|
|
|
(+ hpos i))
|
|
|
|
characters)))
|
|
|
|
characters))
|
|
|
|
|
|
|
|
;;; Display the characters in CHARACTERS,
|
|
|
|
;;; each one FRACTION of the way from its start to its destination.
|
|
|
|
;;; If FRACTION is 0, the characters appear in their starting positions.
|
|
|
|
;;; If FRACTION is 1, the characters appear in their destinations.
|
|
|
|
|
|
|
|
(defun animate-step (characters fraction)
|
|
|
|
(let ((remains (- 1 fraction)))
|
|
|
|
(dolist (item characters)
|
|
|
|
(let ((vpos (+ (* remains (nth 1 item))
|
|
|
|
(* fraction (nth 3 item))))
|
|
|
|
(hpos (+ (* remains (nth 2 item))
|
|
|
|
(* fraction (nth 4 item)))))
|
|
|
|
(animate-place-char (car item) vpos hpos)))))
|
|
|
|
|
|
|
|
;;; Place the character CHAR at position VPOS, HPOS in the current buffer.
|
|
|
|
(defun animate-place-char (char vpos hpos)
|
|
|
|
(goto-char (window-start))
|
2005-03-09 22:50:09 +00:00
|
|
|
(let (abbrev-mode)
|
2001-07-23 09:46:39 +00:00
|
|
|
(dotimes (i vpos)
|
2005-03-09 22:50:09 +00:00
|
|
|
(end-of-line)
|
|
|
|
(if (= (forward-line 1) 1)
|
|
|
|
(insert "\n"))))
|
2001-07-23 09:46:39 +00:00
|
|
|
(beginning-of-line)
|
|
|
|
(move-to-column (floor hpos) t)
|
|
|
|
(unless (eolp) (delete-char 1))
|
|
|
|
(insert-char char 1))
|
|
|
|
|
|
|
|
(defvar animate-n-steps 10
|
|
|
|
"Number of steps to use `animate-string'.")
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun animate-string (string vpos &optional hpos)
|
|
|
|
"Display STRING starting at position VPOS, HPOS, using animation.
|
|
|
|
The characters start at randomly chosen places,
|
|
|
|
and all slide in parallel to their final positions,
|
|
|
|
passing through `animate-n-steps' positions before the final ones.
|
|
|
|
If HPOS is nil (or omitted), center the string horizontally
|
|
|
|
in the current window."
|
|
|
|
(let ((characters
|
|
|
|
(animate-initialize string vpos
|
|
|
|
(or hpos
|
|
|
|
;; HPOS unspecified, so compute
|
|
|
|
;; it so as to center the string.
|
2001-08-01 08:02:45 +00:00
|
|
|
(max 0 (/ (- (window-width) (length string)) 2))))))
|
2001-07-23 09:46:39 +00:00
|
|
|
(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.)
|
|
|
|
(let (buffer-undo-list
|
|
|
|
list-to-undo)
|
|
|
|
;; Display the characters at the Ith position.
|
|
|
|
;; This inserts them in the buffer.
|
|
|
|
(animate-step characters (/ i 1.0 animate-n-steps))
|
|
|
|
;; Make sure buffer is displayed starting at the beginning.
|
|
|
|
(set-window-start nil 1)
|
|
|
|
;; Display it, and wait just a little while.
|
|
|
|
(sit-for .05)
|
|
|
|
;; Now undo the changes we made in the buffer.
|
|
|
|
(setq list-to-undo buffer-undo-list)
|
|
|
|
(while list-to-undo
|
|
|
|
(let ((undo-in-progress t))
|
|
|
|
(setq list-to-undo (primitive-undo 1 list-to-undo))))))
|
|
|
|
;; Insert the characters in their final positions.
|
|
|
|
(animate-step characters 1)
|
|
|
|
;; Put the cursor at the end of the text on the line.
|
|
|
|
(end-of-line)
|
|
|
|
;; Redisplay so they appear on the screen there.
|
|
|
|
(sit-for 0)
|
|
|
|
;; This is so that the undo command, used afterwards,
|
|
|
|
;; will undo the "animate" calls one by one.
|
|
|
|
(undo-boundary)))
|
|
|
|
|
2001-08-10 18:10:40 +00:00
|
|
|
;;;###autoload
|
|
|
|
(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)))))
|
2003-02-04 13:24:35 +00:00
|
|
|
|
2001-08-06 12:40:52 +00:00
|
|
|
;;;###autoload
|
2004-02-21 13:30:42 +00:00
|
|
|
(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\"."
|
2005-09-24 Emilio C. Lopes <eclig@gmx.net>
* woman.el (woman-file-name):
* wid-edit.el (widget-file-prompt-value)
(widget-coding-system-prompt-value):
* w32-fns.el (set-w32-system-coding-system):
* vc.el (vc-version-diff, vc-annotate):
* textmodes/reftex-auc.el (reftex-arg-cite)
(reftex-arg-index-tag):
* textmodes/refer.el (refer-get-bib-files):
* textmodes/artist.el (artist-figlet-choose-font):
* terminal.el (terminal-emulator):
* replace.el (occur-read-primary-args):
* rect.el (string-rectangle, string-insert-rectangle):
* ps-print.el (ps-print-preprint):
* progmodes/pascal.el (pascal-goto-defun):
* progmodes/etags.el (visit-tags-table, visit-tags-table-buffer):
* progmodes/compile.el (compilation-find-file):
* printing.el (pr-interactive-n-up):
* play/animate.el (animate-birthday-present):
* net/rcompile.el (remote-compile):
* man.el (man, Man-goto-section, Man-follow-manual-reference):
* mail/rmailsum.el (rmail-summary-search-backward)
(rmail-summary-search):
* mail/rmailout.el (rmail-output-read-rmail-file-name)
(rmail-output-read-file-name):
* mail/rmail.el (rmail-search, rmail-search-backwards):
* mail/mailabbrev.el (merge-mail-abbrevs, rebuild-mail-abbrevs):
* locate.el (locate):
* international/quail.el (quail-show-keyboard-layout):
* international/mule.el (set-buffer-file-coding-system)
(revert-buffer-with-coding-system, set-file-name-coding-system)
(set-terminal-coding-system, set-keyboard-coding-system)
(set-next-selection-coding-system):
* international/mule-diag.el (describe-coding-system)
(describe-font, describe-fontset):
* international/mule-cmds.el (universal-coding-system-argument)
(search-unencodable-char, describe-input-method)
(set-language-environment, describe-language-environment):
* international/codepage.el (codepage-setup):
* international/code-pages.el (codepage-setup):
* info.el (Info-search, Info-follow-reference)
(Info-search-backward):
* emacs-lisp/advice.el (ad-read-advised-function)
(ad-read-advice-class, ad-clear-cache, ad-activate)
(ad-deactivate, ad-update, ad-unadvise, ad-read-advice-name)
(ad-enable-advice, ad-disable-advice, ad-remove-advice)
(ad-read-regexp):
* ediff-util.el (ediff-toggle-regexp-match):
* ediff-ptch.el (ediff-prompt-for-patch-file):
* dired-aux.el (dired-diff):
* diff.el (diff):
* cus-edit.el (custom-variable-prompt):
* calendar/timeclock.el (timeclock-ask-for-project):
* calc/calcalg3.el (calc-get-fit-variables):
* calc/calc-store.el (calc-edit-variable)
(calc-permanent-variable):
* vc-mcvs.el (vc-mcvs-register):
* shadowfile.el (shadow-define-literal-group):
* woman.el (woman-file-name):
* vc.el (vc-version-diff, vc-merge):
* textmodes/reftex-index.el (reftex-index-complete-tag):
* format.el (format-decode-buffer, format-decode-region):
* emulation/viper-cmd.el (viper-read-string-with-history):
* emacs-lisp/debug.el (cancel-debug-on-entry):
* emacs-lisp/checkdoc.el (checkdoc-this-string-valid-engine):
* ediff.el (ediff-merge-revisions)
(ediff-merge-revisions-with-ancestor, ediff-revision):
* completion.el (interactive-completion-string-reader):
* calc/calc-prog.el (calc-user-define-formula):
Follow convention for reading with the minibuffer.
2005-09-24 13:44:02 +00:00
|
|
|
(interactive (list (read-string "Name (default Sarah): "
|
2004-02-21 13:30:42 +00:00
|
|
|
nil nil "Sarah")))
|
2001-08-06 12:40:52 +00:00
|
|
|
;; Make a suitable buffer to display the birthday present in.
|
2004-02-21 13:30:42 +00:00
|
|
|
(switch-to-buffer (get-buffer-create (format "*%s*" name)))
|
2001-08-06 12:40:52 +00:00
|
|
|
(erase-buffer)
|
|
|
|
;; Display the empty buffer.
|
|
|
|
(sit-for 0)
|
|
|
|
;; Make sure indentation does not use tabs.
|
|
|
|
;; They would confuse things.
|
|
|
|
(setq indent-tabs-mode nil)
|
|
|
|
|
|
|
|
(animate-string "Happy Birthday," 6)
|
2004-02-21 13:30:42 +00:00
|
|
|
(animate-string (format "%s" name) 7)
|
2001-08-06 12:40:52 +00:00
|
|
|
|
|
|
|
(sit-for 1)
|
|
|
|
|
|
|
|
(animate-string "You are my sunshine," 10 30)
|
|
|
|
(sit-for .5)
|
|
|
|
(animate-string "My only sunshine." 11 30)
|
|
|
|
(sit-for .5)
|
|
|
|
(animate-string "I'm awful sad that" 12 30)
|
|
|
|
(sit-for .5)
|
|
|
|
(animate-string "You've moved away." 13 30)
|
|
|
|
(sit-for .5)
|
|
|
|
(animate-string "Let's talk together" 15 30)
|
|
|
|
(sit-for .5)
|
|
|
|
(animate-string "And love more deeply." 16 30)
|
|
|
|
(sit-for .5)
|
|
|
|
(animate-string "Please bring back" 17 30)
|
|
|
|
(animate-string "my sunshine" 18 34)
|
|
|
|
(animate-string "to stay!" 19 34))
|
|
|
|
|
2007-04-05 06:29:42 +00:00
|
|
|
(random t)
|
|
|
|
|
2007-04-05 06:16:18 +00:00
|
|
|
(provide 'animate)
|
|
|
|
|
2003-09-01 15:45:59 +00:00
|
|
|
;;; arch-tag: 275289a3-6ac4-41da-b527-a1147045392f
|
2001-07-23 09:46:39 +00:00
|
|
|
;;; animate.el ends here
|