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.
Although 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.
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
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
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:
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.