home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Hall of Fame
/
HallofFameCDROM.cdr
/
prog1
/
4th_86.lzh
/
MAND.PRO
< prev
next >
Wrap
Text File
|
1989-02-15
|
6KB
|
192 lines
( The following is two routines -- MAND -- and JULIA -- written in UCC Forth.
They are essentially the same as the C code in Jan/Feb '88
MicroCornucopia, but they use the modulus value to determine the plot
color rather than the loop count. This gives pictures much closer to
those in Peitgen & Richter.
The default iteration count is 20 rather than 1000, as this gives
faster plotting, and pictures which are quite reasonable. A new value of
iteration count can be entered on the command line -- 1000 MAND --.
The original code has been "tweaked" in various places, and --
compared with the conventional C-programmed implementations which take
from several hours to a day to complete -- this code is quite speedy.)
( forget new
: new ; )
off printload
: sqr ,dup f* ;
640 const maxcol ( for EGA card)
350 const maxrow
7 const maxcolr ( forget high intensity colours - not used anyway)
2 block MINCOL ( to be bumped between multiple passes)
2 block minrow ( likewise)
2 block maxit ( max number of iterations - entered on command line)
1.0 ,const maxsiz
2 block colr ( single precision variables)
2 block row
2 block col
4 block P ( floating point variables)
4 block Q
4 block modulus
4 block deltaP
4 block deltaQ
4 block Xcur
4 block Xlast
4 block xlasts
4 block Ycur
4 block Ylast
4 block ylasts
4 block deltaX
4 block deltaY
4 block Pmax
4 block Pmin
4 block Qmax
4 block Qmin
4 block Pinc
4 block Qinc
4 block Xmax
4 block Xmin
4 block Ymax
4 block Ymin
: init
0 mincol !
0 minrow !
20 maxit ! ( just in case)
-2.00 Pmin ,! ( alternative values can be loaded from file)
0.5 Pmax ,!
-1.25 Qmin ,!
1.25 Qmax ,!
-1.8 Xmin ,!
1.8 Xmax ,!
-1.8 Ymin ,!
1.8 Ymax ,!
-0.74543 P ,!
0.11301 Q ,!
;
: fred ( loop to evaluate z = z**2 + c )
( xlast ,@ ,dup f* xlasts ,! ylast ,@ ,dup f* ylasts ,! )
getsts if norm q-u-it then
repeat modulus ,@ 4.0 ,< colr @ maxit @ < and
while
xlast ,@ ylast ,@ f- xlast ,@ ylast ,@ f+ f* P ,@ f+
( P + xsq - ysq on stack)
xlast ,@ ,dup f+ ylast ,@ f* Q ,@ f+
( Q + 2xy on stack)
colr @ 1+ colr ! ( needed ONLY for 'while' limit above)
ylast ,!
,dup ,dup xlast ,!
f* ylast ,@ ,dup f* f+ modulus ,!
endwhile
modulus ,@ 10.0 f* integer single ( convert modulus to color value)
case
of[ 0 THRU 1 ] drop 0 colr ! endof
of[ 1 THRU 2 ] drop 1 colr ! endof
of[ 2 THRU 3 ] drop 2 colr ! endof
of[ 3 THRU 4 ] drop 3 colr ! endof
of[ 4 THRU 5 ] drop 4 colr ! endof
of[ 5 THRU 6 ] drop 5 colr ! endof
of[ 6 THRU 7 ] drop 6 colr ! endof
of[ 7 THRU 8 ] drop 6 colr ! endof
( 0 of 0 colr ! endof
1 of 0 colr ! endof
2 of 1 colr ! endof
3 of 2 colr ! endof
4 of 3 colr ! endof
5 of 4 colr ! endof
6 of 5 colr ! endof
7 of 6 colr ! endof )
drop 6 colr ! endcase ;
: draw ( symmetrical draw about horizontal axis )
3 pick maxrow 4 pick - 2 + 3 pick ( mirror parameters)
mincol @ if dpix else d4pix then ( draw bottom to centre)
mincol @ if dpix else d4pix then ; ( draw top to centre)
( dpix draws one pixel - d4pix draws 4 in a row)
: mandd Pmin ,@ P ,!
maxcol mincol @ do ( col is j is P row is i is Q )
Qmin ,@ Q ,!
maxrow 2 / 1+ minrow @ do ( calculate half screen only)
Pmin ,@ j double float deltaP ,@ f* f+ P ,!
Qmin ,@ i double float deltaQ ,@ f* f+ Q ,!
,0 xlast ,!
,0 ylast ,!
,0 modulus ,! 0 colr ! fred
j i colr @ dup if draw else 3 kill ( exit ) then
( no need to draw black pixels)
( Q ,@ Qinc ,@ f+ Q ,! )
8 +loop
( P ,@ Pinc ,@ f+ P ,! )
8 +loop ; ( draw coarse pattern rapidly - then fill in with multiple passes)
: mand init ( depth 0= if 20 then maxit ! ) ( enter parameter on command line)
( or use 20 as default)
egam ( set EGA card to 640 x 350 and blank screen)
Pmax ,@ Pmin ,@ f- maxcol double float 1.0 f- f/ deltap ,!
Qmax ,@ Qmin ,@ f- maxrow double float 1.0 f- f/ deltaq ,!
Pmin ,@ P ,! 8.0 deltaP ,@ f* Pinc ,!
Qmin ,@ Q ,! 8.0 deltaQ ,@ f* Qinc ,!
8 0 do ( multiple staggered passes of mandd loop)
7 0 do mandd
minrow @ 1 + minrow ! 1 +loop
mincol @ dup 0= if 4 + else 1+ then mincol ! 0 minrow ! 1 +loop ;
: jul
maxcol mincol @ do ( col is j is P row is i is Q )
maxrow minrow @ do
0.0 modulus ,! 0 colr !
Xmin ,@ j double float deltaX ,@ f* f+ Xlast ,!
Ymin ,@ i double float deltaY ,@ f* f+ Ylast ,!
fred
j i colr @ dup if
mincol @ if dpix else d4pix then
else 3 kill then
8 +loop
8 +loop ;
: julia init ( depth 0= if 20 then maxit ! ) egam
Xmax ,@ Xmin ,@ f- maxcol double float 1.0 f- f/ deltax ,!
Ymax ,@ Ymin ,@ f- maxrow double float 1.0 f- f/ deltay ,!
8 0 do
7 0 do jul
minrow @ 1 + minrow ! 1 +loop
mincol @ dup 0= if 4 + else 1+ then mincol ! 0 minrow ! 1 +loop ;
: aaa mand ;