Not 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, its an uses simple math to generate an image.
Not really three dimensions.
As hinted by my comment, there isnt any 3D images in the program. Not sure what I was thinking. Everything about the sun is 2D. Heck, its even square. Thats not too surprising given the ZX81s blocky graphics. But, I could have tried at least a little bit. Im 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.
Thats wordy, so below youll 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 isnt 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 ZX81s
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.
Experimentation is good.
Although 3D image doesnt 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 isnt flash and the code is repetitive, but it works. That, ultimately, is what is important.