: s>f ( s -- F: f ) s>d d>f ; : fdup2 ( F: r1 F: r2 -- F: r1 F: r2 F: r1 F: r2 ) fswap fdup frot fdup frot fswap ; : fsquare ( r -- r * r ) fdup f* ; : cdup ( c -- c c ) fover fover ; : c+ ( c1 c2 -- c1 + c2 ) frot f+ frot frot f+ fswap ; : cover ( c1 c2 -- c1 c2 c1 ) 3 fpick 3 fpick ; : cabs ( c -- |c| ) fsquare fswap fsquare f+ fsqrt ; : cmul { F: a F: b F: c F: d -- (ac - bd) (cb + ad) } a c f* b d f* f- c b f* a d f* f+ ; : csquare ( c -- c * c ) cdup cmul ; : cdrop ( c -- ) fdrop fdrop ; : iterate_mandelbrot ( c z -- c z*z + c ) csquare cover c+ ; : eval_mandelbrot ( c max_iteration -- n ) { max_iteration } 0 0.0e 0.0e ( iteration zr zi ) begin dup \ duplicate iteration cdup \ duplicate z cabs 2.0e f<= swap max_iteration < and while iterate_mandelbrot 1 + \ iteration++ repeat cdrop cdrop \ drop c z 1 - ; \ return iteration - 1 : main ( ) s" .:=*+|]%################################### " { lookup_table len } cr 50 0 ?do 100 0 ?do i s>f 50.0e f- 25.0e f/ \ x0 = (x-50) / 25 j s>f 25.0e f- 12.5e f/ \ y0 = (y-25) / 12.5 len eval_mandelbrot lookup_table + 1 type loop cr loop ;