rem Julia Sets ...... Rev 5.2 rem A J Tooth / 1st February 2003 Revised 28th June 2003 rem Set up use of Full Screen proc_fullscreen(22) xlim%=2048 : ylim%=1536 dim Col%(7,6) a$=inkey$(10) rem Parameter Setup print " Either enter your own parameters, or choose a point on the MANDELBROT set." print " Press -m- for the Mandelbrot option, or spacebar to enter your own." rem Sets up eight levels of random colour proc_eight a$=get$ : cls if a$="m" then rem Preset parameters lmt%=127 : rl=-2 : ru=2 : il=-2 : iu=2 : cm%=1000000 rem Initial Mandelbrot picture proc_mandinit else cls : print " Enter personally chosen parameters. " : print input " Iteration limit (65)",lmt% input " Lower real limit (-2)",rl input " Upper real limit (2)",ru input " Lower imag. limit (-2)",il input " Upper imag. limit (2)",iu input " Julia Parameter value 1 (0.45)",cr input " Julia Parameter value 2 (0.7)",ci input " Complex Modulus limit (1,000,000)",cm% endif cls : clg rem Colour scheme options repeat input " Leave colours as random, or choose a range. Enter -d- or -r-. ",ch$ until (ch$="d" or ch$="r") c$=ch$ if c$="r" then proc_colran else rem Random colours already set above endif rem Repeats from here after PROC_zoom 470 cls : clg repeat input " Enter q for quick and s for slow output ",spd$ until (spd$="q" or spd$="s") cls : clg rem MAIN: Iteration Section if spd$="q" then st%=8 else st%=2 for a%= 0 to xlim% step st% for b%= 0 to ylim% step st% rem Set initial values proc_init(cr,ci) stp%=1 : Et%=0 rem Main Procedure for Julia/Mandelbrot calculations proc_julman(cr,ci) rem Go and get the colours proc_cols rem Plots a SINGLE PIXEL move a%,b% : draw a%,b% next b% next a% rem End of Main Body rem Primary Exit & Repeat Options sp$=get$ if sp$="s" then goto 790 if sp$="m" then proc_zoom else run endif goto 470 790 quit end rem End of Programme --------------------------------------- : rem PROC 1 rem Sets Colour Range def proc_colran input " Select base colour. Enter r,g or b. ",bs$ input " Select low(1), medium(2) or high(3) or max(4) intensity. Enter 1,2,3 or 4. ",in% print " Using the same colour for base and range is OK." input " Enter ranging colour (r,g or b). ",rn$ input" Enter third colour (r,g or b) if required or enter (x) if not required. ",ot$ input " Use 64 colour gradations in Slow mode or only 16. Enter -h- or -l-. ",gr$ case gr$ of when "h" : gr%=64 when "l" : gr%=16 endcase case bs$ of when "r" : Red%=63*in% : Green%=0 : Blue%=0 when "g" : Red%=0 : Green%=63*in% : Blue%=0 when "b" : Red%=0 : Green%=0 : Blue%=63*in% endcase endproc : rem PROC 2 rem Set initial values def proc_init(Cr,Ci) local x,y x=rl+(a%/xlim%)*(ru-rl) y=il+(b%/ylim%)*(iu-il) r=x*x-y*y-Cr : i=2*x*y-Ci zmod=sqr(r*r+i*i) endproc : rem PROC 3 rem Set up use of Full Screen def proc_fullscreen(N%) sys "GetSystemMetrics", 0 to xscreen% sys "GetSystemMetrics", 1 to yscreen% sys "SetWindowLong",@hwnd%,-16,&16000000 sys "SetWindowPos",@hwnd%,-1,0,0,xscreen%,yscreen%,0 mode N% mouse off : off : rem Turns off the Mouse Pointer and the Cursor endproc : rem PROC 4 rem Enables user to zoom into a particular area def proc_zoom local x%,y%,b%,ax%,bx%,ay%,by%,rnl,inl mouse on : gcol 7 rem Select first corner of rectangular zoom area repeat mouse x%,y%,b% ax%=x% : ay%=y% until b%=4 rem Print a "+" at the first corner move ax%-10,ay% : draw ax%+10,ay% move ax%,ay%-10 : draw ax%,ay%+10 rem Select opposite corner of zoom area repeat mouse x%,y%,b% bx%=x% : by%=y% until b%=1 rem Draw a box and wait 1 second before moving on move ax%,ay% : draw bx%,ay% : draw bx%,by% draw ax%,by% : draw ax%,ay% a$=inkey$(100) rem Re-assign corner points in ascending order if ax%10 then lev%=10 fct=Ntn%/256 Red%= int(fct*Col%(lev%,1)+(1-fct)*Col%(lev%,4)) Green%=int(fct*Col%(lev%,2)+(1-fct)*Col%(lev%,5)) Blue%= int(fct*Col%(lev%,3)+(1-fct)*Col%(lev%,6)) when "r" : rem Uses custom colours rem Always only uses 16 colours in Quick mode (64 not easy to see!) Ntn%=(256/gr%)*(stp% mod gr%) lev%=stp% div gr% : if lev%>4 then lev%=4 rem Colours alternate between increasing and decreasing in intensity if (lev% mod 2)=1 then Ntn%=gr%-Ntn% case rn$ of when "r" : Red%=Ntn% when "g" : Green%=Ntn% when "b" : Blue%=Ntn% endcase case ot$ of when "r" : Red%=63*lev% when "g" : Green%=63*lev% when "b" : Blue%=63*lev% otherwise rem Do nothing endcase endcase rem Set colour to Black if Zmod remains finite if stp%=lmt% then f%=0 else f%=1 rem Continually reassigns Colour 10 to be the new hue vdu 19,10,16,(f%*Red%),(f%*Green%),(f%*Blue%) gcol 0,10 endproc : rem PROC 6 rem Main Julia / Mandelbrot Routine def proc_julman(Cr,Ci) local rnex, inex repeat rem Iterates calculation of Fn(Z)=Z*Z-c rem Then checks how big Fn(Z) is, until it exceeds some limit stp%=stp% + 1 rnex=r*r-i*i-Cr : inex=2*r*i-Ci r=rnex : i=inex zmod=sqr(r*r+i*i) rem Press spacebar to "crash" out the programme and start again if inkey(-99) then quit rem Set loop exit criteria if zmod>cm% then Et%=1 if stp%=lmt% then Et%=1 until Et%=1 endproc : rem PROC 7 rem Draws initial Mandelbrot Set to select Julia parameters from def proc_mandinit local x,y,p%,q% for p%= 0 to xlim% step 4 for q%= 0 to ylim%/2 step 4 rem Set initial values x=rl+(p%/xlim%)*(ru-rl) y=il+(q%/ylim%)*(iu-il) r=x*x-y*y-x : i=2*x*y-y zmod=sqr(r*r+i*i) crt=x : cit=y stp%=1 : Et%=0 rem Calculate Mandelbrot Set proc_julman(crt,cit) rem Go and get the colours proc_cols rem Plots a SINGLE PIXEL move p%,q% : draw p%,q% move p%,1536-q% : draw p%,1536-q% next q% next p% rem Enables selection of Julia parameter using the mouse. mouse on 3 : gcol 7 repeat mouse real%,imag%,m% X=rl+(real%/xlim%)*(ru-rl) Y=il+(imag%/ylim%)*(iu-il) print tab(5,2);"Click on the left mouse button at an interesting point." print tab(5,5);"Present Point is; ";X;",";Y;" "; until m%=4 cr=X : ci=Y print tab(5,7);"Julia Parameters selected." b$=inkey$(100) mouse off endproc : rem PROC 8 rem Sets up eight levels of random colours def proc_eight for s%=0 to 7 c$="d" : cs%=rnd(3) rem Singles out one of the primary colours as prevalent Rinit%=-63*(cs%=1)+rnd(191) Ginit%=-63*(cs%=2)+rnd(191) Binit%=-63*(cs%=3)+rnd(191) Col%(s%,1)=Rinit% : Col%(s%,2)=Ginit% : Col%(s%,3)=Binit% Col%(s%,4)=int(Ginit%/2) Col%(s%,5)=int(Binit%/2) Col%(s%,6)=int(Rinit%/2) next s% endproc