Apple II Saturn Reborn
Growing up, I had a love for computers the first time we got them in our 6th grade class. The Apple II. I was so amazed by this device that could output graphics and sound, and those could be used in games or applications or whatever, from programs entered entirely by the user. Oregon Trail was one of the class favorites, something very minimal in regards to a game, but it was more interactive than anything else we had at the time.
Even though I desparately wanted an Apple computer, I knew there was no way my parents could afford one. So in middle school, I would spend lunch hours and time after school in the computer lab, using the computer books and magazines from either the school or the local library as references and punching in the programs contained within, key by key, before I had taken any typing class.
One of the programs was from the "Graphics for the Apple" book (pictured above). It was just called "Saturn", and it would draw a shaded model of Saturn with rings. I thought this was just one of the coolest things ever - an actual 3D shaded model on an Apple! At the time, most every game was 2D, and for good reason - this personal computer was one of the first, and was of course, not powerful at all. I do remember a 3D wireframe game that came out later, Stellar 7, which I really enjoyed and thought was another amazing achievment, actual 3D gameplay in real time.
At the time, I had no idea how the program worked. Sure, the book explained how the code worked, but I had no idea how any of these sines and cosines and matrix transformations worked - I wouldn't be introduced to trigonometry until my junior year of high school. For the most part I would just key in the programs, line by line, making sure to copy exactly what was written. After debugging and getting the program to run, the only thing that was rather disappointing was how long it took to run. If I made the size of Saturn and the rings large enough to fill the 140 by 80 pixel screen, it took just forever to run. We're talking like a pixel or two every second. Even back then, I knew that BASIC programs were much slower than ones made in Assembler, but I wasn't prepared for it to be quite so slow.
Decades later, being experienced with computers and programming, I ran across the "Graphics For The IBM PC" book online, recognizing the pixelated yellow picture of Saturn on the cover, and bought it for nostalgic reasons. I wouldn't find the Apple version until later, which I of course picked up as well, seeing as that's the original book I had, and also, I had over the years picked up some old Apple II / IIc / IIe computers that I could still use to program if I wanted.
I had always kicked around the idea of making the original program work on modern hardware, but the idea was usually supplanted with another project that was more interesting. I finally got around to dusting off the books and try to run it in a web browser using the canvas element. I thought it was going to be more difficult than it was. The hardest part was recreating some of the logic in the program: within a few IF/THEN statements were some GOTO and GOSUB statements that go to specific line numbers of the program - programming constructs that aren't used in modern languages anymore, and for good reason. However, back in the day, they were the only way to accomplish complicated logic branching using the limited BASIC instruction set.
I made a few changes to the code. One was the smoothing factor of the shading, I turned that up, since I felt it was way too blocky. Interestingly, the cover of the books shows the shading as more smooth; I have a feeling they changed the code making the shading to be blockier in order for it to run faster, since it was already dreadfully slow. There are shading and arc routines and such in the canvas toolset, but I didn't want to recreate it using those, I wanted the same pixel-by-pixel code. So I simply use the canvas fillRect() method to make small rectangles for the pixels. The original code did the rings and shading by using for-loops and plotting out lines, which ends up creating some interesting moiré patterns, which I wanted to preserve. The code would also ask for inputs. In this version, I just created sliders. I also included sliders for the light vector direction, which wasn't part of the original code. I increased the space between the rings and Saturn a bit. Also, 140x80 pixels is a bit small, so I bumped it up to 640x400. Still using the original Apple's amazing white/cyan/magenta hi-res color pallete, however.