Drawing cylinders on the ZX81


A fun little math program that draws a twisted cylinder.

I wrote this back in august and just gettin around to publishing. It was first shared in my BASIC group, but the ZX81 lacks a lot of the functionsabilty for it to work well. Undetereed, I hacked at the program to not only display the twisted cylinder, but also add a bit of randomness to the effort.

# Needing a line.
The first hurdle to overcome was to add a line drawing routine. Foruatnly, I'd done this a few times with other programs. I grabbed the routine from my drawing program. With that in place, I could now replicate the math of the original program to see how it worked.

Once I had the line drawing routine, I got to work formatting the program. Although I usually didn't bother as a teenager, I try to make the programs a bit more logical now. It's easy enough to use a GOSUB to manage logic. Doesn't hurt to add a comment or two as well using REM. The end result is a little easier to read program.

Cylinder, ZX81 Screenshot #1 by Steven Reid, 2025Cylinder, ZX81 Screenshot #1 by Steven Reid, 2025

# Plotting is so hard.
Although I couldn't do much about the slowness of the program, I could fix another issue I ran into. The ZX81 plots from the bottom left corner. This caused the cylinder to be inverted. Not quite what I planned.

To get around that, I invested the plots. Fortunately, that required only some basic math adjustments. Instead of LET X1=X1/4.4 I did this: LET X1=64-X1/4.4. Not too difficult a change, but it looks better. I also mirrored the Y access although I probably didn't need to.

Cylinder, ZX81 Screenshot #2 by Steven Reid, 2025Cylinder, ZX81 Screenshot #2 by Steven Reid, 2025

This got me to the point of testing the program. Although it worked, it was a bit big. To size the cylinder, I scaled down the plot points. Thus, the /4.4 part of the code above. It not only fixed the display, but also made the cylinder fit on the screen.

# Adding a bit more interest.
Although the program looked decent, it was a dull. To spice things up a it, I added some randomness to the cylinder's shape. This ensured that each new cylinder looked a bit different, making the program more of a screen saver. To make the cylinder more random, I just added touch of randomness to the variables. They look like this:

1000 REM **SET VARS**
1010 LET D=1.95
1020 LET S=PI/10
1030 RAND 0
1040 LET UR=30+RND*70
1050 LET LR=40+RND*60

The UR and LR determine the twist of the cylinder and make it a bit easier to see.

Cylinder, ZX81 Screenshot #3 by Steven Reid, 2025Cylinder, ZX81 Screenshot #3 by Steven Reid, 2025

And with that, I wrap up this month's program.



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