13. Hank's Adventures in Generative Art

The C128 sure looks great, doesn't it? All those vivid, flat colors, formed in the soft glow of a CRT monitor. It's good stuff. That plastic-and-iron box running the show has a bit of computing power behind it, too - maybe we can use those resources to make ourselves a bit of art. Maybe we can even write a program that makes that art look a little different every time it's run!

Here's a relatively simple program to help us accomplish the task -



This code introduces some basic (and I do mean BASIC) concepts revolving around graphics on the 8-bit Commodore line, and I haven't talked too much about BASIC on this site as of yet. Let's go through this one line by line.

Beginning at line 10, the little reverse-heart character clears the screen. We can type it by holding the SHIFT key and hitting the CLR/HOME key.

Our next two lines (20 and 25) are POKE commands that use the RND function to assign a random color to the screen border (frame) and background (center portion), which correspond to memory locations 53280 and 53281 respectively. "INT(RND(1)*16" randomly generates a floating-point value between 0.0 and 1.0, multiplies it by 16 (giving us a value between 0 and 15, rounding down), then converts it to an integer (as the screen colors are assigned to discrete integers rather than floating-point values).

The next few lines will run in a loop to select one of a set of 4 graphics characters and repeatedly print them on the screen. Line 30 is A=INT(RND(1)*4)+1. As you may be able to guess, this gives us a value between 1 and 4 (notice the +1 at the end to increment the results of the RND function - otherwise we'd get a value between 0 and 3). It stores this number in the variable A.

The following four lines either print a character (if the corresponding value is stored in A), or do nothing and skip to the next BASIC statement. Note that the ";" at the end of the statement keeps the computer's on-screen cursor from skipping to a new line with each character printed.

Line 80 loops back to line 30, and the process continues until the RUN/STOP key is pressed or the computer is turned off.



Look at those results!

The fun in this sort of program obviously lies with the near-infinite ways in which it can be modified. We can use different text art characters to experiment with varying patterns (/ and \ make for a good start). Going back to the example of that reverse-heart character that cleared the screen, the Commodore also supports similar "control characters" to change text color - as the current program only prints in a single color, an extra loop could be set up at the beginning of the program to pick a different color each time the program is run. You could also modify the program to output the results to a line printer instead of your monitor or TV screen, or even re-direct it to a file stored on a floppy disk or cassette tape to save your particularly-pretty attempts.

If you're feeling inspired, use this program as a template to whip up some generative art of your own and send along the results to me via e-mail!


This site is copyright 2023 Hank Wesley Chorkin. If you don't like it, you can get out!

Back