Saturday, May 27, 2017

Here are a few programs I've been using to benchmark the math changes.
I didn't write most of it, so if it does something stupid it's not my fault.  :)


10 W=500:DIM F(W):P=1:A=3:F(P)=A
20 FOR P=2 TO W
30 A=A+2:X=1
40 S=A/F(X):IF S=INT(S) THEN 30
50 X=X+1:IF X<P AND F(X)*F(X)<=A THEN 40
60 F(P)=A
70 NEXT P


10 REM PRIME NUMBER GENERATOR
20 FOR X=1 TO 1000
30 FOR Y=2 TO X-1
40 IF X/Y=INT(X/Y) THEN 70
50 NEXT Y
60 PRINT X
70 NEXT X



This simple BASIC mandelbrot generator required some porting, but it mostly works now.
The original used a MOD function in line 110 which has been replaced, but it has some issues with negative numbers.  The IF THEN was enough to get it running but it's not a proper fix.
The step rate has been cut in half to adjust for 40 columns, but for a benchmark it might be better to use 80 columns, and build a string array with the results instead of just printing them.  That would test some string functions as well as math, and the results could be compared for differences.
It does the job for now.

You could use this as the basis for a graphic version if you adjust the step rate to match the graphics resolution, replace the print with SET() or equivalent function, replace the string with an integer array containing the color numbers you want to use, and replace 5 with the number of colors in your graphics mode.


10 REM SIMPLE MANDELBROT GENERATOR USING TEXT
20 X0=-2: X1=0.5: Y0=-1: Y1=1: I1=20
30 X2=0.06: Y2=0.2: D$=" .-=#"
40 FOR Y=Y0 TO Y1 STEP Y2
50 FOR X=X0 TO X1 STEP X2
60 Z0=0: Z1=0
70 FOR I=1 TO 11
80 Z2=Z0*Z0-Z1*Z1: Z3=2*Z0*Z1
90 Z0=Z2+X: Z1=Z3+Y: IF Z0*Z0+Z1&gt;4 THEN GOTO 110
100 NEXT I
110 IF Z0 AND Z1 &gt; 0 THEN PA=SQR(Z0*Z0+Z1):A=(PA-(5*INT(PA/5)))+1:C$=MID$(D$,A,1):PRINT C$;
120 NEXT X: PRINT
130 NEXT Y

No comments:

Post a Comment