1 ! Copyright (C) 2005, 2009 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-scale ( -- x ) width 200000 zoom-fact * / ; inline
10 : y-scale ( -- y ) height 150000 zoom-fact * / ; inline
12 : scale ( x y -- z ) [ x-scale * ] [ y-scale * ] bi* rect> ; inline
14 : c ( i j -- c ) scale center width height scale 2 / - + ; inline
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 <iota> [ width <iota> swap '[ _ c pixel color write ] each ] each ; inline
31 "P6\n" write width pprint bl height pprint "\n255\n" write
32 binary encode-output ; inline
34 : mandel-benchmark ( -- )
35 "mandel.ppm" temp-file binary [ ppm-header render ] with-file-writer ;
37 MAIN: mandel-benchmark