factor/extra/benchmark/mandel/mandel.factor

48 lines
1.3 KiB
Factor
Raw Normal View History

2008-09-01 19:28:24 -04:00
USING: arrays io kernel math math.functions math.order
math.parser sequences locals byte-arrays byte-vectors io.files
io.encodings.binary 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
: iter ( c z nb-iter -- x )
2008-09-01 19:28:24 -04:00
dup 0 <= [ 2nip ] [
over absq 4.0 >= [ 2nip ] [
>r sq dupd + r> 1- iter
] if
] if ; inline recursive
2007-09-20 18:09:08 -04:00
2008-07-04 11:52:50 -04:00
: x-inc width 200000 zoom-fact * / ; inline
2007-09-20 18:09:08 -04:00
: y-inc height 150000 zoom-fact * / ; inline
: c ( i j -- c )
2008-09-01 19:28:24 -04:00
[ x-inc * center real-part x-inc width 2 / * - + >float ]
[ y-inc * center imaginary-part y-inc height 2 / * - + >float ] bi*
2007-09-20 18:09:08 -04:00
rect> ; inline
2008-09-01 19:28:24 -04:00
:: render ( accum -- )
2007-09-20 18:09:08 -04:00
height [
width swap [
2008-09-01 19:28:24 -04:00
c C{ 0.0 0.0 } nb-iter iter dup zero?
[ drop B{ 0 0 0 } ] [ color-map [ length mod ] keep nth ] if
accum push-all
2007-09-20 18:09:08 -04:00
] curry each
2008-09-01 19:28:24 -04:00
] each ; inline
2007-09-20 18:09:08 -04:00
2008-09-01 19:28:24 -04:00
:: ppm-header ( accum -- )
"P6\n" accum push-all
width number>string accum push-all
" " accum push-all
height number>string accum push-all
"\n255\n" accum push-all ; inline
2007-09-20 18:09:08 -04:00
2008-09-01 19:28:24 -04:00
: buf-size ( -- n ) width height * 3 * 100 + ; inline
2007-09-20 18:09:08 -04:00
2008-03-11 22:58:50 -04:00
: mandel ( -- data )
2008-09-01 19:28:24 -04:00
buf-size <byte-vector>
[ ppm-header ] [ render ] [ B{ } like ] tri ;
2007-09-20 18:09:08 -04:00
2007-11-25 00:50:12 -05:00
: mandel-main ( -- )
2008-03-11 22:58:50 -04:00
mandel "mandel.ppm" temp-file binary set-file-contents ;
2007-09-20 18:09:08 -04:00
MAIN: mandel-main