all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Pascal Bourguignon <pjb@informatimago.com>
To: help-gnu-emacs@gnu.org
Subject: Re: simple elisp animation?
Date: Thu, 27 Mar 2008 21:08:24 +0100	[thread overview]
Message-ID: <87iqz8q69z.fsf@thalassa.informatimago.com> (raw)
In-Reply-To: 1de26e7c-e77c-47e2-b823-5e94fbddb9fb@a23g2000hsc.googlegroups.com

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:

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



-- 
__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	other threads:[~2008-03-27 20:08 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-27 16:50 simple elisp animation? someusernamehere
2008-03-27 17:56 ` Lennart Borgman (gmail)
     [not found] ` <mailman.9507.1206640618.18990.help-gnu-emacs@gnu.org>
2008-03-27 18:11   ` someusernamehere
2008-03-27 20:08     ` Pascal Bourguignon [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87iqz8q69z.fsf@thalassa.informatimago.com \
    --to=pjb@informatimago.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.