Saturday, September 2, 2017

Return to old school programming

When my brother and I were growing up, our parents brought home an Apple II personal computer. Actually ours was one of the first Apple "clones," a Franklin ACE 1000, but it ran all of the original Apple software. And more importantly, you could write your own programs with the included AppleSoft BASIC.

My brother and I cracked open the computer guide that came with it, and slowly taught ourselves how to write programs in BASIC. My first attempts were fairly straightforward math quizzes and other simple programs. But as I gained more experience in BASIC, I was able to harness high resolution graphics mode and do all kinds of nifty things.

AppleSoft BASIC was my first programming language. And while I eventually moved on to other compiled languages (I prefer C) and other programming environments, I think I'll always have a soft spot for AppleSoft BASIC.

BASIC was a very simple programming language. Two-letter variable names, line numbers, and other hallmarks were typical for AppleSoft BASIC. But even within these limitations, you could create pretty impressive programs if you were clever.

Recently, I've been spending free time playing around with an Apple II emulator, writing a few simple programs as a "throwback" to that old school programming. The Apple IIjs emulator runs in your web browser and very effectively simulates running an old Apple II computer from the 1980s. You can find other Apple II emulators specifically for Linux.

I want to share a program I recently wrote on Apple IIjs: a chaos generation of the Sierpinski Triangle. If you aren't familiar with this method to generate the Sierpinski Triangle, the brief rules are:

  1. Set three points that define a triangle (A,B,C)
  2. Randomly select a point anywhere (x,y)
  1. Randomly select one of the triangle's points (A,B,C)
  2. Set the new x,y to be the midpoint between the previous x,y and the triangle point
  3. Repeat

And with this rule set, I created a very simple iteration of the Sierpinski Triangle. This sample uses the standard graphics resolution mode (GR) with 40×40 pixels.

The code to generate this image is fairly straightforward:

Two thousand steps takes forever to run on the simulated 6502 microprocessor, by the way. Just like computing in the 1980s.

For a more interesting view of the Sierpinski Triangle on the Apple II, it helps to switch to a higher resolution. Apple's high resolution mode (HGR) allowed a whopping 280×192 pixels.

This requires changing two lines of code: line 50 sets HGR mode instead of GR mode, and line 140 uses HPLOT instead of PLOT.

I don't have our original Franklin ACE 1000 anymore, or an original Apple II computer, but at least I can return to old school programming whenever I like by using an emulator.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.