factor/extra/benchmark/mandel/mandel.factor

38 lines
1.2 KiB
Factor
Raw Normal View History

! Copyright (C) 2005, 2009 Slava Pestov.
2008-09-10 19:22:50 -04:00
! See http://factorcode.org/license.txt for BSD license.
2008-09-11 21:01:10 -04:00
USING: io kernel math math.functions sequences prettyprint
io.files io.files.temp io.encodings io.encodings.ascii
io.encodings.binary fry benchmark.mandel.params
benchmark.mandel.colors ;
2008-07-04 11:52:50 -04:00
IN: benchmark.mandel
2007-09-20 18:09:08 -04:00
: x-scale ( -- x ) width 200000 zoom-fact * / ; inline
: y-scale ( -- y ) height 150000 zoom-fact * / ; inline
2007-09-20 18:09:08 -04:00
: scale ( x y -- z ) [ x-scale * ] [ y-scale * ] bi* rect> ; inline
: c ( i j -- c ) scale center width height scale 2 / - + ; inline
2007-09-20 18:09:08 -04:00
2008-09-10 19:22:50 -04:00
: count-iterations ( z max-iterations step-quot test-quot -- #iters )
'[ drop @ dup @ ] find-last-integer nip ; inline
: pixel ( c -- iterations )
[ C{ 0.0 0.0 } max-iterations ] dip
2008-09-10 23:11:40 -04:00
'[ sq _ + ] [ absq 4.0 >= ] count-iterations ; inline
2008-09-10 19:22:50 -04:00
: color ( iterations -- color )
[ color-map [ length mod ] keep nth ] [ B{ 0 0 0 } ] if* ; inline
: render ( -- )
height iota [ width iota swap '[ _ c pixel color write ] each ] each ; inline
2008-09-10 19:22:50 -04:00
: ppm-header ( -- )
2008-09-11 21:01:10 -04:00
ascii encode-output
2013-03-14 22:24:00 -04:00
"P6\n" write width pprint bl height pprint "\n255\n" write
2008-09-11 21:01:10 -04:00
binary encode-output ; inline
2007-09-20 18:09:08 -04:00
: mandel-benchmark ( -- )
2008-09-11 21:01:10 -04:00
"mandel.ppm" temp-file binary [ ppm-header render ] with-file-writer ;
2007-09-20 18:09:08 -04:00
MAIN: mandel-benchmark