Mandelbrot Viewer (simple)
Community Forums/Showcase/Mandelbrot Viewer (simple)
| ||
Good Morning, seeing the other thread in the general discussion on Mandelbrot stuff I thought I'd post a simple program that views the Mandelbrot Set and zooms in (higher zoomfactor = more gradual zoom, should be between 0 and 1 - but greater than 1). Press Escape at any time to exit. I've left some code commented out which captures each frame as a bitmap, in case you want to put together a movie later.. The code was written in blitzplus but should also work in blitz3d. Not sure if it will work on blitzmax, may need to change the writepixelfast and lockbuffer. Now, if blitz3d/plus had double precision floats we could zoom in further, however I wonder if there is a way to increase the floating point precision in some other means... Graphics 512,512,0,2 SetBuffer BackBuffer() Const zoomfactor#=0.5 Global cx#,cy#,scale#,limit,lp,a1#,b1#,a2#,b2#,x,y,ax#,ay# cx=0 cy=0 scale=0.02; limit=4; Repeat LockBuffer For x=-256 To 255 For y=-256 To 255 ax=cx+x*scale ay=cy+y*scale; a1=ax b1=ay lp=0 Repeat If KeyDown(1) Then End lp=lp+1; a2=a1*a1-b1*b1+ax; b2=2*a1*b1+ay; a1=a2 b1=b2; Until (lp>767) Or ((a1*a1)+(b1*b1)>limit) If lp>767 Then lp=0 If lp<256 Then col=lp If lp>255 And lp<512 Then col=(255 Or ((lp-256) Shl 8)) If lp>511 Then col = (255 Or (255 Shl 8) Or ((lp-512) Shl 16)) WritePixelFast(x+256,y+256,col) If lp > 100 And lp < 600 newcx#=cx+scale*Float(x) newcy#=cy+scale*Float(y) EndIf Next Next cx=newcx cy=newcy If cx<>0 Or cy<>0 Then scale=scale*zoomfactor# UnlockBuffer If scale < 0.00000001 Then End ;frame=frame+1 ;SaveBuffer BackBuffer(),"mandelbrot_"+Str(frame)+"0.bmp" ;Text 0,0,scale ;Text 0,20,"cx:"+cx+" cy:"+cy Flip If MouseHit(1)<>0 Then cx=cx+scale*Float(MouseX()-256) cy=cy+scale*Float(MouseY()-256) scale=scale/2 EndIf Until KeyDown(1) WaitKey End |
| ||
Edit - For some reason I cannot copy the code from the listing above into blitzplus without all sorts of garbage appearing in the code listing???? Edit - Ahh - copy to notepad first. Last edited 2010 |
| ||
It's amazing that a formula that small can create a structure so complex. |
| ||
Nice one man, i love this stuff. Check out this guy: http://www.hpdz.net/TechInfo.htm Very low level stuff with the CPU, joining 32 bit numbers together to get, well practically unlimited resolution, depending on how long you'll live i suppose :) |
| ||
Here is a nice variation of the mandelbrot set, the "Mandelbrot Lake" with an infinite river. Digged out of a very old computer magazin from the 80s :-D![]() |