help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: simple elisp animation?


From: Pascal Bourguignon
Subject: Re: simple elisp animation?
Date: Thu, 27 Mar 2008 21:08:24 +0100
User-agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/22.1.50 (gnu/linux)

someusernamehere <someusernamehere@gmail.com> writes:

> On 27 mar, 11:56, "Lennart Borgman (gmail)"
> <lennart.borg...@gmail.com> wrote:
>
>> Can't you just use run-with-timer and replace the content?
>
>
> mmmm, but with this I need to wrote the entire content of two (or
> more) animation positions,
> I have in mind some work with coordinates (which I dont know how in
> elisp)

(require 'cl)
(deftype character () 'fixnum "") ; emacs lisp characters are fixnums.
(defun character (object)
  (etypecase object
    (character object)
    (string    (aref object 0))))


(defun* set-pixel (x y &optional (color "*"))
  (goto-char (point-min))
  (insert (make-string (forward-line y) (character "\n")))
  (beginning-of-line)
  (let ((width (- (save-excursion (end-of-line) (point)) (point))))
    (when (<= width x)
      (end-of-line)
      (insert (make-string (- x width -1) (character " "))))
    (beginning-of-line)
    (forward-char x)
    (delete-char 1)
    (insert (character color))))

(loop
   with base = 40
   for i from 0 to 80
   do (set-pixel i
                 (round (+ base (* 20 (sin (* 2 pi (/ i 80.0))))))
                 (+ 32 i)))



But of course, it would be much much more efficient to erase the old
region and insert a new one in block, than doing it pixel by pixel
like this. (I mean, character by character of course).


For example, you can play movies with:

(defun pjb-animate (speed)
  (interactive "nSpeed: ")
  (let ((delay (/ 1.0  speed))
        (done  nil))
    (widen)
    (goto-char (point-min))
    (message "Animating...")
    (while (not done)
      (widen)
      (if (search-forward "\f" nil 'at-limit)
        nil
        (goto-char (point-max))
        (setq done t))
      (narrow-to-page)
      (sit-for delay)
      (force-mode-line-update t)
      ) ;;while
    (message "Done.")))

Just draw each pictures, one per page (pictures separated with
form-feeds, Control-L, that you can enter with C-q C-l), and 
M-x pjb-animate RET them.

For example:


___

/\_

 __/

 ___

 /\_

  __/

  ___

  /\_

   __/

   ___

   /\_

    __/

    ___

    /\_

     __/



-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

CONSUMER NOTICE: Because of the "uncertainty principle," it is
impossible for the consumer to simultaneously know both the precise
location and velocity of this product.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]