When I was a lad, I used to spend hours writing programs on the family Commodore. Generally they consisted of some top-secret security clearance screens (with flashing lights and passwords and everything. Completely uncrackable, usually even for me, but trivial to bypass if you had some familiarity with the List command) followed by many screens of text. I used BASIC as the world’s least practical word processor. I never took the time (nor, possibly, had the aptitude, but I cleverly avoided having to look that question head-on by not taking the time) to dig deeper into BASIC’s capabilities. I left that to my brother, and now he writes software for a living and I think it’s neat that my blog has its own URL, so things seem to have worked out as they were meant to.
Still, though, I spent many an hour typing out BASIC code numbered line by numbered line, so when I got caught up in a conversation at work about Sierpinksi triangles I thought it might be fun to write a program to make one myself.
Sierpinski triangles are formed by designating three points of a triangle, then picking a random point within those points. From that random point, move halfway to a randomly chosen vertex, and then from that point move halfway to a randomly chosen vertex, and so on. They’re used as chaos theory illustrations – order developing as iterations increase. I learned about them in Jason, Mark, and Julie’s science capstone presentation at Wartburg, and you can check out the Wikipedia page if you’re interested.
Finding a BASIC compiler and learning its particular nomenclature ended up taking far more time than actually writing the program did; turns out that even a far-from-expert like me can write a Sierpinski Triangle maker in a dozen lines of code. It’s crazy to watch unfold on the screen, though. All those random points end up looking like this:
Cool, huh? That’s a million points (which brings up an incidental point: modern computers are much faster than Commodore 128′s). If you look about halfway up to the left of the triangle you can see the first few points. I didn’t bother limiting the first random point to the triangle – it could pick any point within the full square. So it picked a point a little outside, and then chose to go halfway to the upper left vertex for its next two dots. Then the next 999,998 are correctly within the triangle boundaries.
Kind of fun to relive some childhood nerdish tendencies. Go, BASIC! (No criticism allowed from any professional programmers who read this (there used to be at least 2, but maybe they’ve cleared their RSS feeds and moved on).)