Re: Animation (was Re: (Q) Keeping copies of drawing areas)

Niels P. Mayer (mayer@netcom.com)
Wed, 22 Jun 94 09:45:02 -0700

> OK, here's Hanoi in Tk. It displays a bitmap on the background, not a
> GIF file, because (as far as I know) Tk currently only supports bitmap
> objects. This is not as fancy as the WINTERP version (no menu to
> choose number of pegs etc.) but gives nice smooth animation.

Not quite a fair comparison in terms of your "with less code" boast. Using
a line-for-line rewrite of your code, which is significantly less abstract
than mine, I believe the line counts would be very similar. Also it looks
like yours is simpler graphically. I think (haven't run it) the following
are the differences:

(0) Try it with objects. Your 'report' is significantly more complex than
I would think necessary. You've got a lot of "state" residing within
the same scope, making it hard to tell what will affect what.
(1) No text on pegs; no "base" to pegs;
(2) All objects are rectangles. I use ovals for my discs, these are harder
to animate smoothly because you've got to repaint the background GIF
"around" the oval as it moves. Doing animations with squares is easy
and will not indicate whether a system handles 2.5 D animation of stacked
images correctly. More interesting/difficult are shapes that are
"transparent" in some places and occlusions that are not rectangular.
(3) WHen moving between pegs, does the object trace a smooth arc path
between the pegs. In the code I posted, the :TAP_TRAVERSE routine
will create multiple frames of animation in showing an object moving
from point A to point B. Furthermore in the case of moving discs
between pegs, :TAP_TRAVERSE/:CLOCKWISE creates a smooth arc of motion
as the disc moves between pegs.
(4) Hanoi doesn't even come close to showing off the full capabilities of
WINTERP 2.0; I think your "smooth" animation (explicitly iterating
motion over the canvas) will get pretty hairy once you start trying to
have multiple objects move simultaneously, e.g. multiple layers moving
simultaneously. (See :TX_COMPOSE).

FYI, when I sat down to do the tower of hanoi problem, I ended up just
replacing the canonical symbol-based tower of hanoi (see 'hanoi' below)
with an animated version where the stacking-peg image objects were "dropped
in" to replace the symbols A, B and C. Then I replaced 'print-move' with
code that sends the appropriate messages to the stacking peg image objects:
basically one message to pop a disk from one stacking peg, another to move
the disk from one peg to the next, and finally a message to push a disk
onto the other stacking peg. And then I wrote STACKING-PEG-IMAGE-CLASS (and
BOXED-TEXT-IMAGE-CLASS) to handle all the "stateful" aspects of the
animation....

; Good ol towers of hanoi
;
; Usage:
; (hanoi <n>)
; <n> - an integer the number of discs

(defun hanoi(n)
( transfer 'A 'B 'C n ))

(defun print-move ( from to )
(princ "Move Disk From ")
(princ from)
(princ " To ")
(princ to)
(princ "\n")
nil)

(defun transfer ( from to via n )
(cond ((equal n 1) (print-move from to ))
(t (transfer from via to (- n 1))
(print-move from to)
(transfer via to from (- n 1)))))

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
== Niels Mayer -- netcom!mayer -- mayer@netcom.com ==
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=