Sometimes one function can do a lot. For Februarys program, picture uses a line drawing routine to draw a pretty picture. Okay, pretty is in the eye of the beholder. But, nonetheless, it is a picture. The fun, though, is in watching it draw.
A computer and a boat, together are art.
A like the way Picture draws its boat. Starting with a blank slate, it draws a serious of lines to build up to the final product. The process looks great, even if the resolution is low. Other games and programs of this era did something similar. Although, I didnt learn of them until much later in life.
Coincidence? I doubt it. Using a drawing routine with points of data has some distinct advantages. In particular, it saves memory over storing a bitmap display, which can be quite large. Besides that, programs can also use it to generate many pictures.
Using a data structure, such as an array, would have made the programs more flexible. Want more complex images? Add a few more drawing functions, like circle or fill routines. Although Picture doesnt do this, it could have.
Ill add a final comment about the drawing function. It's slow. Related to the computing power of the ZX81, the picture takes time to build because of how slow the computer is. If you did this on a modern computer, the effect would break. For such a simple image, I expect it would take an instant. Yet, you could fix that with a delay routine if you wanted to replicate the effect.
Bunches of branches.
Digging into the code, you will find that it follows a strict pattern. Lets look at the first few lines of the program.
110 LET X=25
111 LET Y=7
112 LET X1=60
113 LET Y1=Y
114 GOSUB 8050
120 GOSUB 9000
The first two lines set the starting point variables X and Y. The next two set the ending point variables X1 and Y1. Line 114 jumps to the routine that draws a line between those two points. At last, line 120 goes to the function that sets makes the end point the new starting location.
And that is it. Over and over again, some variation of these four actions take place to draw the boat. To do that, Picture needs to draw twenty lines. Evensun is a series of lines because there is no circle function. Simple and functional, it isnt very efficient.
Looking at the program now, I could have eliminated all the
GOSUB 9000 lines. Instead, I should have set the end point after drawing the line. Every place where I I didnt use this, I set the X and Y variables anyway. A savings of fifteen lines of code in total.
Im pretty sure the math function I use to draw the line I found in one of my books. The math makes sense to me now, having taken a graphic program course in college, I doubt I understood it at the time. It doesnt matter though. It worked, and that was all I needed.
Yet, as good a job as it did, it was slow. Very slow. The ZX81 offers flexible math functions that allow it to be very versatile, much more so than some of its peers. But other limitations hurt it, as noted above. Writing these routines in assembly would be faster, but this program wouldnt be the same.
Ideas and endings.
If you want a challenge, and like ZX81 BASIC, try rewriting Picture without the
LET statements. I can think of a couple of ways to do it using arrays, as discussed before. Want more? How about without any
GOSUB routines? This program is simple enough, it should be possible using
Even more challenging, it would be fun to create a game using these ideas. You could always use the ZX81s
FAST mode to speed up the drawing. I can think of a few ideas already. Man, I miss writing games on this little guy.
With that, I leave you with ideas and a boat.
Originally published at www.reids4fun.com on January 22, 2017.