Saturday, January 15, 2011

Mandelbrot? Mandelbrot!

I like that dude! Have you met him? He's a real charmer that Benoit... you better watch yourself. He's also as clever as clever gets. Not clever as us Canadians use the word, more "British" clever. Meaning he's just a really smart dude. After listening to the song Mandlebrot Set by Jonathon Coulton I thought I'd try and get my trusty Ti-83 Plus to draw me a pretty picture. Considering I'm not a math major and have a very limited knowledge of programming in general. I had to figure out first does the Mandlebrot Set have a describing equation? what the hell is it? and finally how to program a calculator to draw it. The Wikipedia page for the Mandelbrot Set was all I needed, it even gave me the psuedocode to get going. At the end of the day the Ti-basic code looked like this:

prgmMNDLBRT
1  :FnOff : ClrDraw
2  :PlotsOff
3  :AxesOff
4  :-2.5->Xmin:1->Xmax
5  :-1->Ymin:1->Ymax
6  :For(T,-1,1,2/64)
7  :For(S,-2.5,1,3.5/96)
8  :prgmMNDLBRT2
9  :If I=M
10 :Pt-On(S,T)
11 :End
12 :End
13 :StorePic 1

Basically all that is going on is the program goes through every pixel of the screen. There are 64x96 pixels on the screen so each point on a screen simply needs to be calibrated for the range of x and y values, hence the 2/64 and 3.5/96. It checks the program below and will only turn that pixel on if MNDLRBRT2 outputs I=M. I split this up into two programs for simplicity's sake but in reality you only need one. There is more background info on the wiki page, but that's the basics.

pgrmMNDLBRT2
1  :0->X:0->Y
2  :10->M:0->I
3  :While X*X+Y*Y<=4 and I<M
4  :2XY+T->Z
5  :X*X-Y*Y+S->X
6  :Z->Y
7  :I+1->I
8  :End
9  :Return

At first the calculator didn't seem to be doing anything, but it was running. So I decided to half the iterations by telling the for loops in prgmMNDLBRT to iterate by 4/64 and 7/96 respectively. This way only half the pixels on the screen would be tested. Again a few minutes passed and finally a little pixel went dark! Soon after there was another, and another! I hadn't been this excited since Christmas in 1994 when my grandparents gave me a turtle wheelbarrow. The final result look like this:
  Iterations per pixel (M) :10, Time to finish: 19 minutes. Good? I don't think so lets try 100 iterations per (every other) pixel:
 Iterations per pixel: 100, Time to finish: 70 minutes.This looked pretty neat, but I was not satisfied and decided to see what happened if I let my calculator take its sweet time with every pixel:

Iterations per pixel: 10, Time to finish: ~70minutes.

 Iterations per pixel: 100, Time to finish: ~180minutes.

 Iterations per pixel: 250, Time to finish: ~480minutes. For this one I started it before bed, checked it in the morning and still had to wait for another 2 hours. But the end result was pretty sweet. Too bad the Ti series calculators didn't have colour screens. That would be too much nerd to handle.

-Rois

No comments:

Post a Comment