Spirographs in Adobe PostScript

I read a page on Mathworld about spirographs, and thought that it would be fun to write a throw-away PostScript program to draw them. The resulting program is tiny and fun to run, so I have included it here. This is an example output screen:

A spirograph curve

A good way to run the program is with GhostScript, a free PostScript interpreter and previewer; you can download it for the Macintosh, Windows, or UNIX platforms. Better yet, just send your program directly to a PostScript printer! (But be sure to convince the printer to directly render the PostScript, or it might confuse the program with ordinary text [and do the wrong thing].) Change the bottom three parameters of the program to alter the resulting spirograph! Now, isn't this more fun than the actual toy? (Well, perhaps not, but what do you want for free? :)

Finally, for those of you in science and mathematics, note that PostScript is a pretty cool language to hack, since you can do things like this in no time at all; start with Adobe's PostScript Language Tutorial and Cookbook (I believe that you can download it from free from Adobe as a PDF). (If you need to debug Monte-Carlo simulations, for example, is is often a great idea to have your program dump a PostScript file which prints the status of what you're doing.)

Kleanthes Koniaris, email.