Wednesday, August 22, 2018

Mandelbrot in BASIC

This Mandelbrot generator was ported from a 'C' program but I'm not sure where I found the code.
It was a work in progress of the version I used to generate the Mandelbrot image for my picture on Zoom, but it's missing some of the final changes that were lost when Microsoft nuked me.
On the later version, I combined a few lines, changed some logic, and probably placed some constants in variables to make it run faster.  Let's face it, when you are running something like this on an interpreter on a sub 2MHz processor... small improvements can cut quite a bit off of the render time.  It took just over 12 hours to finish without any patches. 
With the multiply patch it should run in 9 hours... ish... but I didn't get a chance to time it.

It's not that I like BASIC so much, but programs that take a long time to finish make it easier to compare the results of small patches to the interpreter.

100 POKE65495,0
110 PMODE4,1:PCLS1:SCREEN1,1
120 MG=3/4: REM reciprocal of magnify * 3
130 XC=-1:YC=0: REM center of picture
140 TC=2: REM Two Constant
150 z=0: REM Zero Constant
160 XR=1/256: REM XR= reciprocal of X Resolution
170 YR=1/192: REM YR= reciprocal of Y Resolution
180 XA=XR/2:YA=YR/2: REM coordinate adjustments
190 SF=1/640: REM Reciprocal of 640, used to divide by 640
200 ST=2/640: REM same as above but * 2
210 IT=50: REM IT= Number of iterations to do
240 REM XS=X Squared  YS=Y Squared
250 FOR YC=1TOYR
260   FOR XC=1TOXR

'        ca = (xcoord - 320) / 640 * wid + xcenter

'        cb = (ycoord - 100) / 640 * 2 * wid + ycenter

270     CA=(XC*XR)*MG-.7
280     CB=(YC*YR)*MG

270     CA=(XC-320)*SF*WD+XC
280     CB=(YC-200)*ST*WD+YC

290     X=Z:Y=Z
300     FORT=1TOIT
310       XS=X*X:YS=Y*Y
320       X=XS-YS+CA:Y=TC*X*Y+CB
330       IF XS+YS > 100 THEN T=IT:PSET(XC,YC,0)
360     NEXTT
370   NEXTXC
380 NEXTYC
390 END

No comments:

Post a Comment