What Can You Do with a Simple ZX81 Animation?


Slow Down, December's monthly program, happily uses the ZX81 against itself to slow down an animation.

Slow Down, ZX81 screen shot, by Steven Reid, 1985Although may of my early programs were games, I spent a fair amount of time experimenting. Decemberís program, Slow Down, is one of my animation experiments. It is a straight forward sprite animation, with a twist. I used the ZX81 against itself to slow it down. If youíre ready, letís dig deeper.

Transformative animation.
I must have had fun animating the ball as it turned into a robot, a ship, and back into a ball. For the life of me, I donít remember this program much. But, Iím sure I could find the scribblings in my folder if I searched enough. In any case, the animation is neatóif not useful.

Looking at it all these years later, it reminds me of sprites. On other computers back then, you could move sprites around, animating them in the background. They were great for games, and one could use these concepts in a similar way. Unfortunately, the ZX81 doesnít have a sprite system. So, instead you get this simple animation.

Yet, I did learn how to create sprites later on my C64 and my friendís TI99. Those systems animated them using bitmapped layers, making them more complex. The ZX81 used character based graphics, which are easier but less flexable. Unfortunately, I didnít print them out or otherwise keep a copy of them, and are now lost to time. Instead, Iím left with their spiritual precursor.

How to hammer your processor.
To animate the transformation, I used a series of PRINT statements. Each one acts as a frame for the animation. In some cases, I repeat the framesóa pause within the animation. It looks nice, if not detailed.

Each frame of the program includes a simple line of code: LET L=VAL A$. At the start of the program, A$ is set to a single value: ď0Ē. Although this still introduces a slight delay, it isnít enough to notice. For the first run, the animation runs at full bore.

For the second run, the A$ is set to something a bit more noticeable. Using math functions such as SIN and TAN takes more time for the ZX81 to compute. As such, using the following code adds enough delay to slow down the animation.

A$="SIN PI*SIN PI+TAN PI"

I use PI, or π, here to reduce memory consumption. Unlike numbers that usually take five bytes, PI only uses one. A neat trick, if not necessary I this case. Plus, itís easy to type.

As a note, I thought the use of PI was unique to the ZX81. I didnít run across it on other PCís in the earlier 80ís. But, as I researched, I found that it did end up the BASIC 7.0 for the Commodore 128. Some modern languages define it as a constant, usually when including a math library.

Also, I learned that there are ways to compute it: 4*ARCTAN(1) or ARCCOS(-1). Of course, you could skip the whole message and define it yourself. I knew π was special, but didnít realize how many variations one could use to define it. And thatís before weíve discussed precision.

Low-level programming is good for the programmer's soul.
– John Carmack

For our purpose, though, the use of PI fits. The ZX81 churns on those math functions, slowing down the animation on the next run. If anything, Iím annoyed at the row of print statements and repetitious nature of the code. If I was doing more with this, Iíd rather have stored the frames in an array.

An array would have advantages beyond refactoring the code. For one, I could wrap it in a FOR loop, reducing the repetition of the code. Another use would be if I was using the transformation as a sprite. I could move it around the screen, or inject other code, while still maintaining the frame order.

Fast or slow, it works.
As a demo, Slow Down does a fine. The animation is interesting, if not earth shattering. I'm sure I spent more time on that then the program. By 1985, Iíd already used the ideas from this animation in real games. With nothing new, the program is a test of old ideas wrapped into a pretty package. They canít all be groundbreaking.



Comments on this article:

No comments so far.

Write a comment:

Type The Letters You See.
[captcha image][captcha image][captcha image][captcha image][captcha image][captcha image]
not case sensitive