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.files.temp io.encodings io.encodings.ascii
5 io.encodings.binary fry benchmark.mandel.params
6 benchmark.mandel.colors ;
9 : x-inc ( -- x ) width 200000 zoom-fact * / ; inline
10 : y-inc ( -- y ) height 150000 zoom-fact * / ; inline
13 [ x-inc * center real-part x-inc width 2 / * - + >float ]
14 [ y-inc * center imaginary-part y-inc height 2 / * - + >float ] bi*
17 : count-iterations ( z max-iterations step-quot test-quot -- #iters )
18 '[ drop @ dup @ ] find-last-integer nip ; inline
20 : pixel ( c -- iterations )
21 [ C{ 0.0 0.0 } max-iterations ] dip
22 '[ sq _ + ] [ absq 4.0 >= ] count-iterations ; inline
24 : color ( iterations -- color )
25 [ color-map [ length mod ] keep nth ] [ B{ 0 0 0 } ] if* ; inline
28 height [ width swap '[ _ c pixel color write ] each ] each ; inline
32 "P6\n" write width pprint " " write height pprint "\n255\n" write
33 binary encode-output ; inline
36 "mandel.ppm" temp-file binary [ ppm-header render ] with-file-writer ;