3D Image is July’s ZX81 Program


A ZX81 animation experiment using a super nova as its subject.

3D Image, Screen Shot, ZX81, Steven Reid 1984Not everything I wrote on the ZX81 was a game, although I did write a lot of those. In fact, some of my first computer programs did nothing more than print pictures. 3D Image, a badly named program, is one of my experiments in animation on the ZX81. Depicting a sun at the end of its life, it’s a uses simple math to generate an image.

Not really three dimensions.

As hinted by my comment, there isn’t any 3D images in the program. Not sure what I was thinking. Everything about the sun is 2D. Heck, it’s even square. That’s not too surprising given the ZX81’s blocky graphics. But, I could have tried at least a little bit. I’m sure I was aiming for something more, but the result is not 3D.

Enlarger, showcased in February of 2013, better represents a 3D image, if only just. At least the object presented looked round. Even so, 3D Image tells a story, which is more than Enlarger does. Perhaps not the happiest of stories, but it adds a little flare to an otherwise simple program.

The text is what makes the experiment more interesting. Without the story, the program is just a square changing size. Using a simple explanation, 3D Image engages your imagination and gives you a reason to watch.

Simple code for simple shows.

The sun, as well as the explosion, is just a couple of loops. The variable A presents each frame of the animation. There is then another loop that determine the X axis of the object. It is a simple calculation, dividing A in half and subtracting and adding values to it to center the sun as it changes.

The Y axis, which is static, is calculated in the print statement itself. Similar to X, it divides A by 2, but it only calculates the beginning of the line. Lastly, sun is calculated using a string slice based on the value of A.

That’s wordy, so below you’ll find the actual code. Straight forward enough, but the math could have been tightened up a bit. As written, though, I could position the sun elsewhere if desired.

30 FOR S=11-A/2+5 TO 10-A/2+5+A
40 PRINT AT S,10-A/2-.5;"__________"( TO A)
50 NEXT S

The rest of the code isn’t my best. First, it duplicates a lot. The routine for the sun collapsing and exploding are almost exactly the same. Using some variables and GOSUB, I could have represented both with a single function. Doing so would have shrunk this already short program in half.

Another negative is that I ended up using the ZX81’s FAST command to quickly update the image. This has the effect of causing the screen to flicker on a real ZX81. Not very pleasing. I should have avoided it by looking for other ways to improve the speed.

Part of the slowness is due to clearing and repainting the screen each frame. Although needed to display shrinking sun, it is also used during the explosion. That was unnecessary and should be removed. Using the Javascript emulator, though, it actually doesn’t look bad.

Experimentation is good.

Although 3D image doesn’t live up to its name, it is still a success. Experimentation is how we learn, and this is a window looking back at my adventures in programming. Perhaps it isn’t flash and the code is repetitive, but it works. That, ultimately, is what is important.



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