1 ! Copyright (C) 2005, 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: io kernel math math.functions sequences prettyprint
4 io.files io.encodings io.encodings.ascii io.encodings.binary fry
5 benchmark.mandel.params benchmark.mandel.colors ;
8 : x-inc width 200000 zoom-fact * / ; inline
9 : y-inc height 150000 zoom-fact * / ; inline
12 [ x-inc * center real-part x-inc width 2 / * - + >float ]
13 [ y-inc * center imaginary-part y-inc height 2 / * - + >float ] bi*
16 : count-iterations ( z max-iterations step-quot test-quot -- #iters )
17 '[ drop @ dup @ ] find-last-integer nip ; inline
19 : pixel ( c -- iterations )
20 [ C{ 0.0 0.0 } max-iterations ] dip
21 '[ sq _ + ] [ absq 4.0 >= ] count-iterations ; inline
23 : color ( iterations -- color )
24 [ color-map [ length mod ] keep nth ] [ B{ 0 0 0 } ] if* ; inline
27 height [ width swap '[ _ c pixel color write ] each ] each ; inline
31 "P6\n" write width pprint " " write height pprint "\n255\n" write
32 binary encode-output ; inline
35 "mandel.ppm" temp-file binary [ ppm-header render ] with-file-writer ;