8-Bit Software Online Conversion

Mandelbrot Program - Listing

10REM >Mandel 20REM by Steven Flintham 30REM 40REM Version 1.00 50REM 60REM A simple Mandelbrot program 70: 80MODE 7 90VDU 23;8202;0;0;0; 100PROCdisable 110PROCinit 120PROCget`details 130MODE mode% 140VDU 23;8202;0;0;0; 150PROCplot`set 160REPEAT UNTIL INKEY-99 170PROCenable 180END 190: 200DEF PROCdisable 210REM NEXT REM TEMP 220REM *FX229,1 230*FX4,2 240ENDPROC 250: 260DEF PROCenable 270*FX229 280*FX4 290ENDPROC 300: 310DEF PROCinit 320ON ERROR MODE 7:REPORT:PRINT " at l ine ";ERL:PROCenable:END 330DIM oscli% 256 340ENDPROC 350: 360DEF PROCtitle 370VDU 26,12 380PRINTTAB(5,0);CHR$141;CHR$132;CHR$1 57;CHR$131;"Mandelbrot set plotter ";CH R$156 390PRINTTAB(5,1);CHR$141;CHR$132;CHR$1 57;CHR$131;"Mandelbrot set plotter ";CH R$156 400PRINTTAB(0,3); 410ENDPROC 420: 430DEF PROCget`details 440LOCAL 450REPEAT 460PROCtitle 470PRINT "Please enter the following, pressing"'"RETURN after each number." 480PRINT'"Lower limit of real componen t:"'CHR$131;:min`real=VAL(FNinput(1,15)) 490PRINT'"Upper limit of real componen t:"'CHR$131;:max`real=VAL(FNinput(1,15)) 500PRINT''"Lower limit of complex comp onent:"'CHR$131;:min`complex=VAL(FNinput (1,15)) 510PRINT'"Upper limit of complex compo nent:"'CHR$131;:max`complex=VAL(FNinput( 1,15)) 520IF min`real>=max`real OR min`comple x>=max`complex THEN PRINT''"The lower li mits must be less that the"'"upper limit s.":PROCspace 530UNTIL min`real<max`real AND min`com plex<max`complex 540PRINT''"Maximum number of iteration s:";CHR$131; 550max`iterations%=VAL(FNinput(1,3)) 560PROCtitle 570PRINT "Which mode do you want to us e? (0, 2, 4"'"or 5)";CHR$131; 580REPEAT 590*FX21 600mode%=GET-48 610UNTIL mode%=0 OR mode%=2 OR mode%=4 OR mode%=5 620PRINT ;mode% 630y`res%=256 640IF mode%=0 THEN x`res%=640:max`col% =1:screen`start%=&3000 650IF mode%=2 THEN x`res%=160:max`col% =7:screen`start%=&3000 660IF mode%=4 THEN x`res%=320:max`col% =1:screen`start%=&5800 670IF mode%=5 THEN x`res%=160:max`col% =3:screen`start%=&5800 680PRINT'"Enter a filename to save the screen as or just press RETURN if you d on't want to save it. The screen save wi ll fail if you are using a shadow screen mode."'"Filename:";CHR$131; 690filename$=FNinput(0,30) 700ENDPROC 710: 720DEF PROCspace 730PRINT'"Press SPACE to continue..." 740*FX21 750REPEAT UNTIL GET=32 760ENDPROC 770: 780DEF FNinput(min%,max%) 790LOCAL xpos%,ypos%,text$,key% 800xpos%=POS 810ypos%=VPOS 820text$="" 830REPEAT 840REPEAT 850*FX21 860key%=GET 870UNTIL key%=13 OR (key%>=32 AND key% <=127) 880IF key%=127 AND LEN(text$)>0 THEN V DU 127:text$=LEFT$(text$,LEN(text$)-1) 890IF key%<>127 AND key%<>13 AND LEN(t ext$)<max% THEN VDU key%:text$=text$+CHR $(key%) 900UNTIL (key%=13 AND LEN(text$)>=min% ) 910=text$ 920: 930DEF PROCplot`set 940LOCAL pixel`width%,pixel`height%,X% ,Y%,real,complex,iterations% 950pixel`width%=1280/x`res% 960pixel`height%=1024/y`res% 970FOR Y%=0 TO y`res%-1 980FOR X%=0 TO x`res%-1 990real=min`real+((max`real-min`real)/ x`res%)*X% 1000complex=min`complex+((max`complex-m in`complex)/y`res%)*Y% 1010iterations%=FNmandelbrot(real,compl ex) 1020GCOL 0,FNcolour(iterations%) 1030PLOT 69,X%*pixel`width%,Y%*pixel`he ight% 1040NEXT 1050NEXT 1060IF filename$<>"" THEN PROCoscli("Sa ve "+filename$+" FFFF"+STR$~screen`start %+" FFFF8000") 1070ENDPROC 1080: 1090DEF FNmandelbrot(k`real,k`complex) 1100LOCAL iterations%,z`real,z`complex, old`z`real,magnitude 1110iterations%=0 1120z`real=0:z`complex=0 1130REPEAT 1140iterations%=iterations%+1 1150REM square z... 1160old`z`real=z`real 1170z`real=z`real^2-z`complex^2 1180z`complex=2*old`z`real*z`complex 1190REM add k... 1200z`real=z`real+k`real 1210z`complex=z`complex+k`complex 1220REM find magnitude of z... 1230magnitude=SQR(z`real^2+z`complex^2) 1240UNTIL iterations%=max`iterations% O R magnitude>2 1250=iterations% 1260: 1270DEF FNcolour(iterations%) 1280IF max`col%=1 THEN =(iterations% MO D 2) 1290IF iterations%=max`iterations% THEN =0 1300=(iterations%/max`iterations%*max`c ol%)+1 1310: 1320DEF PROCoscli($oscli%) 1330LOCAL X%,Y% 1340X%=oscli% MOD 256 1350Y%=oscli% DIV 256 1360CALL &FFF7 1370ENDPROC