]> gitweb.factorcode.org Git - factor.git/blob - extra/benchmark/mandel/mandel.factor
Revert "core: find-last-integer -> find-last-integer-from for symmetry"
[factor.git] / extra / benchmark / mandel / mandel.factor
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 ;
7 IN: benchmark.mandel
8
9 : x-scale ( -- x ) width  200000 zoom-fact * / ; inline
10 : y-scale ( -- y ) height 150000 zoom-fact * / ; inline
11
12 : scale ( x y -- z ) [ x-scale * ] [ y-scale * ] bi* rect> ; inline
13
14 : c ( i j -- c ) scale center width height scale 2 / - + ; inline
15
16 : count-iterations ( z max-iterations step-quot test-quot -- #iters )
17     '[ drop @ dup @ ] find-last-integer nip ; inline
18
19 : pixel ( c -- iterations )
20     [ C{ 0.0 0.0 } max-iterations ] dip
21     '[ sq _ + ] [ absq 4.0 >= ] count-iterations ; inline
22
23 : color ( iterations -- color )
24     [ color-map [ length mod ] keep nth ] [ B{ 0 0 0 } ] if* ; inline
25
26 : render ( -- )
27     height <iota> [ width <iota> swap '[ _ c pixel color write ] each ] each ; inline
28
29 : ppm-header ( -- )
30     ascii encode-output
31     "P6\n" write width pprint bl height pprint "\n255\n" write
32     binary encode-output ; inline
33
34 : mandel-benchmark ( -- )
35     "mandel.ppm" temp-file binary [ ppm-header render ] with-file-writer ;
36
37 MAIN: mandel-benchmark