REM Julia Cosine ...... Rev 6.0 REM A J Tooth / 1st February 2003 Revised 28th June 2003 ON ERROR IF (ERR=17) THEN QUIT REM Set up use of Full Screen PROC_fullscreen(22) xlim%=2048 : ylim%=1536 DIM Col%(7,6) REM Parameter Setup PRINT " This program is the COSINE(Z/C) version of the Mandelbrot/Julia Sets." PRINT : 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$ : CLG IF a$="m" THEN REM Preset parameters lmt%=97 : rl=-2 : ru=2 : il=-2 : iu=2 : cm%=100 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 : ext%=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,com x=rl+(a%/xlim%)*(ru-rl) y=il+(b%/ylim%)*(iu-il) com=Cr*Cr-Ci*Ci : IF ABS(com)<0.01 THEN com=0.01 arg=(Cr*y-Ci*x)/com IF ABS(arg)>10 THEN sg=SGN(arg) : arg=sg*10 r=(COS((Cr*x+Ci*y)/com))*FN_cosh(arg) i=-(SIN((Cr*x+Ci*y)/com))*FN_sinh(arg) 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%7 THEN lev%=7 fct=inten%/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!) inten%=(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 inten%=gr%-inten% CASE rn$ OF WHEN "r" : Red%=inten% WHEN "g" : Green%=inten% WHEN "b" : Blue%=inten% 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,com REPEAT REM Iterates calculation of Fn(Z)=COS(Z/C) REM Then checks how big Fn(Z) is, until it exceeds some limit stp%=stp% + 1 com=Cr*Cr-Ci*Ci : IF ABS(com)<0.01 THEN com=0.01 arg=(Cr*i-Ci*r)/com IF ABS(arg)>10 THEN sg=SGN(arg) : arg=sg*10 rnex=(COS((Cr*r+Ci*i)/com))*FN_cosh(arg) inex=-(SIN((Cr*r+Ci*i)/com))*FN_sinh(arg) 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 RUN REM Set loop exit criteria IF zmod>cm% THEN ext%=1 IF stp%=lmt% THEN ext%=1 UNTIL ext%=1 ENDPROC : REM PROC 7 REM Draws initial Mandelbrot Set to select Julia parameters from DEF PROC_mandinit LOCAL x,y,p%,q%,com FOR p%= 0 TO xlim% STEP 8 FOR q%= 0 TO ylim%/2 STEP 8 REM Set initial values x=rl+(p%/xlim%)*(ru-rl) y=il+(q%/ylim%)*(iu-il) com=x*x-y*y : IF ABS(com)<0.01 THEN com=0.01 r=(COS((x*x+y*y)/com)) : i=0 zmod=SQR(r*r+i*i) crt=x : cit=y stp%=1 : ext%=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 REM COSH Function DEF FN_cosh(X) cosh=(EXP(X)+EXP(-X))/2 =cosh REM SINH Function DEF FN_sinh(X) sinh=(EXP(X)-EXP(-X))/2 =sinh