# BASIC 'Twisted Transcendentals' 1.22

(1 review)

## 7 Screenshots

This weekend, I decided to play with X16 BASIC using the emulator and wound up making an X16 adaptation/extension of a short program for the Plus/4 that appeared in 'The Transactor' journal decades ago. The program uses three parameters: "S" (squiggles/spokes/segments), "W" (wave factor), and "A" (amplitude).  Using X16 BASIC's extensions in terms of bitmap drawing commands, it outputs a neat design with lots of color and a surprising amount of visual variety.

The original Plus/4 program just plotted in black and white and had some built in limitations (and at least two bugs), but I decided to extend the program, add a menu, and upload it after I added color and decided these were fairly cool looking results from such a short simple BASIC routine.

It strikes me as a cool demo because with just three core parameters, you can get an astonishing range of outputs. Of course, like many graphics demos based on stacking transcendental functions, there are combos of inputs where the functions will sort of fall apart and produce something akin to a kiddo scribbling with crayons , but there are also weird "islands" in the domain of possible parameter combinations where order re-asserts itself, both in terms of what gets drawn and (because colors are picked by an AND mask over one of the function variables) how the colors play out.     Note that I included a sample screen shot about some weirdness you can get with very high numbers.   Mostly that is  the result of my simple use of .01745 to convert between degrees and radians, and is caused by amplifying that really simplified rounding of  PI/180.

There are 4 'modes' of operation you can pick from the menu.   You can specify inputs for S, W and A manually; the program can run a sequence with fixed S and A while incrementing W; there is a mode that tries to picks random parameters within several domains where the program produces nice outputs; and there's one that just reads the inputs from some "presets" in DATA statements.  (You can of course add your own 'best of' examples by adding data statements between lines 432 and 499).

I always considered myself a passable BASIC programmer, but this weekend showed me I'm really sort of rusty so please go easy on me if I did something inefficiently or especially 'dumb' in my implementation. The main output routine is extremely crunched (sorry, not sorry) and I did some further things to optimize from the original program for purposes of getting  a bit more performance out of the main routine.    Although it absolutely crawled on the Plus4, I think its fairly impressive on the X16 especially if you look at the sheer amount of sines, cosines, multiplications, and variable fetches /updates that occur during an entire cycle through the primary output drawing loops.

The X16's 40 column mode (SCREEN \$00) was used to key this in and format it, so its probably best if listed/ displayed/reviewed in that mode,   Tested on emulator r.38, and I don't see anything in the pending updates for the next emulator release that would break anything here.

If there are questions about why/how I did something I'll be happy to answer. In fact, if there's any interest in a more detailed write-up of this short and fairly simple program (e.g., section by section, and line-by-line), I would be happy to give it a shot, especially if there are folks new to Commodore BASIC that might find it useful.  It seems to me there are many highly advanced programmers for the X16 posting on this site who are using assembly, C, and even languages they are developing themselves.  Its amazing!  However,  its surely the case that part of the mission of the X16 is to get some newbies involved, and from where I sit, that really does mean getting some more content up here written in BASIC. Keeping that in mind,  I'll probably be diving back into more old issues of The Transactor to do more conversions for the X16 and will continue to upload as long as I'm still having fun with BASIC.   Cheers.

## What's New in Version 1.22See changelog

Released

So I decided to revisit this program using some of my own advice from the BASIC conversion/optimization thread I put in the 'HOWTOS' section.  To be sure, version 1 was already significantly optimized as compared to the original type-in listing from 1985.  But it turns out there was still a lot of room for improvement!

I'm pleased to say that the result of really pushing for speed was an average of another 27%+ reduction in plotting time per image/design compared with the last version.   Its visually faster as it is putting up pixels.   The main trick this time was to factor out parts of calculations it turns out only need to be calculated once per image.  The loop in line 3 prepares these values first, with the results dumped into arrays that are then fetched from within the main routines.  The trade off is a cost of about 1K of extra memory use for the arrays.    Also I found some expression combinations that further simplified things and also saved time.

As before, you can change the variable in line 1 to a '0' to suppress the splash/intro/demo animation that normally occurs when the program is first run.   But in this update there is a new behavior:  Whether or not you have changed line 1 to suppress the intro/demo generally, if you "ESC" (runstop) out of the program instead of just exiting from the main menu, then the next time you run the program it will automatically skip the splash screen and go straight to the menu.

I can elaborate a bit more on the optimization in case its not clear what is going on there.

Yes

## try_it_start_prg

TWISTED-TRANSCENDENTALS-1PT22.PRG
• 9

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

• This will not be shown to other users.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×

This reminds me of a "screensaver" I wrote in Turbo Pascal which had many modes based on polar coordinates - drawing spirals, "spyrographs," squiggly snakey lines crawling around, etc. It's neat to watch math make pictures. And I agree with your observation that the community could use some content for newbie-level members who aren't up to talking about bus timing, latches, compiler internals, etc. This program definitely fits the bill.