X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=blobdiff_plain;f=examples%2Fmandelbrot.4th;fp=examples%2Fmandelbrot.4th;h=c75ebd0f3054acff1d3174bfe7184f1696e7ff47;hb=e8fdb1e66ea6d3790e7b7d7b44676418c0081626;hp=254628ccb9e387e1d50377df9937296ad564fbd3;hpb=87f54f6de003167f7bf388232a827bbd01ba24b3;p=forth.jl.git diff --git a/examples/mandelbrot.4th b/examples/mandelbrot.4th index 254628c..c75ebd0 100644 --- a/examples/mandelbrot.4th +++ b/examples/mandelbrot.4th @@ -1,4 +1,12 @@ -( --- Complex integer arithmetic --- ) +( --- Complex arithmetic --- ) + +( Location of floating point. ) +: precision 10000 ; + +: >scaled precision 10 / * swap precision * + ; + +( Redefine multiplication. Yay forth! ) +: * precision */ ; : c* ( x1 y1 x2 y2 -- x3 y3 ) swap -rot ( x1 x2 y1 y2 ) @@ -28,15 +36,22 @@ : inSet? ( cr ci -- res ) - 100 0 DO + 100 0 do - 2SWAP 2DUP 5 ROLL 5 ROLL + 2swap 2dup 5 roll 5 roll iterate - 2DUP cmagsq - 100 > IF - LEAVE - THEN + 2dup cmagsq + 100 > if + leave + then + + loop +; + +( Draw the Mandelbrot Set!) +: mandel ( x1 y1 x2 y2 -- ) - LOOP ; +( Clean up - hide non-standard multiplication def. ) +hide *