1 ! Copyright (C) 2005, 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: arrays io kernel namespaces math math.functions
4 math.order math.parser sequences byte-arrays byte-vectors
5 io.files io.encodings.binary fry make benchmark.mandel.params
6 benchmark.mandel.colors ;
9 : x-inc width 200000 zoom-fact * / ; inline
10 : y-inc 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 % ] each ] each ; inline
31 "P6\n" % width # " " % height # "\n255\n" % ; inline
33 : buf-size ( -- n ) width height * 3 * 100 + ; inline
36 buf-size <byte-vector>
37 [ building [ ppm-header render ] with-variable ] [ B{ } like ] bi ;
40 mandel "mandel.ppm" temp-file binary set-file-contents ;