benchmark.mandel: clean up the code a bit without changing performance
- use iota when iterating over integers - clean up 'c' worddb4
parent
dee151432c
commit
1813896d14
|
@ -1,5 +1,5 @@
|
||||||
USING: math math.order kernel arrays byte-arrays sequences
|
USING: math math.order kernel arrays byte-arrays sequences
|
||||||
colors.hsv benchmark.mandel.params accessors colors ;
|
colors.hsv accessors colors fry benchmark.mandel.params ;
|
||||||
IN: benchmark.mandel.colors
|
IN: benchmark.mandel.colors
|
||||||
|
|
||||||
: scale ( x -- y ) 255 * >fixnum ; inline
|
: scale ( x -- y ) 255 * >fixnum ; inline
|
||||||
|
@ -11,10 +11,10 @@ CONSTANT: sat 0.85
|
||||||
CONSTANT: val 0.85
|
CONSTANT: val 0.85
|
||||||
|
|
||||||
: <color-map> ( nb-cols -- map )
|
: <color-map> ( nb-cols -- map )
|
||||||
dup [
|
[ iota ] keep '[
|
||||||
360 * swap 1 + / sat val
|
360 * _ 1 + / sat val
|
||||||
1 <hsva> >rgba scale-rgb
|
1 <hsva> >rgba scale-rgb
|
||||||
] with map ;
|
] map ;
|
||||||
|
|
||||||
: color-map ( -- map )
|
: color-map ( -- map )
|
||||||
max-iterations max-color min <color-map> ; foldable
|
max-iterations max-color min <color-map> ; foldable
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
! Copyright (C) 2005, 2008 Slava Pestov.
|
! Copyright (C) 2005, 2009 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: io kernel math math.functions sequences prettyprint
|
USING: io kernel math math.functions sequences prettyprint
|
||||||
io.files io.files.temp io.encodings io.encodings.ascii
|
io.files io.files.temp io.encodings io.encodings.ascii
|
||||||
|
@ -6,13 +6,12 @@ io.encodings.binary fry benchmark.mandel.params
|
||||||
benchmark.mandel.colors ;
|
benchmark.mandel.colors ;
|
||||||
IN: benchmark.mandel
|
IN: benchmark.mandel
|
||||||
|
|
||||||
: x-inc ( -- x ) width 200000 zoom-fact * / ; inline
|
: x-scale ( -- x ) width 200000 zoom-fact * / ; inline
|
||||||
: y-inc ( -- y ) height 150000 zoom-fact * / ; inline
|
: y-scale ( -- y ) height 150000 zoom-fact * / ; inline
|
||||||
|
|
||||||
: c ( i j -- c )
|
: scale ( x y -- z ) [ x-scale * ] [ y-scale * ] bi* rect> ; inline
|
||||||
[ x-inc * center real-part x-inc width 2 / * - + >float ]
|
|
||||||
[ y-inc * center imaginary-part y-inc height 2 / * - + >float ] bi*
|
: c ( i j -- c ) scale center width height scale 2 / - + ; inline
|
||||||
rect> ; inline
|
|
||||||
|
|
||||||
: count-iterations ( z max-iterations step-quot test-quot -- #iters )
|
: count-iterations ( z max-iterations step-quot test-quot -- #iters )
|
||||||
'[ drop @ dup @ ] find-last-integer nip ; inline
|
'[ drop @ dup @ ] find-last-integer nip ; inline
|
||||||
|
@ -25,7 +24,7 @@ IN: benchmark.mandel
|
||||||
[ color-map [ length mod ] keep nth ] [ B{ 0 0 0 } ] if* ; inline
|
[ color-map [ length mod ] keep nth ] [ B{ 0 0 0 } ] if* ; inline
|
||||||
|
|
||||||
: render ( -- )
|
: render ( -- )
|
||||||
height [ width swap '[ _ c pixel color write ] each ] each ; inline
|
height iota [ width iota swap '[ _ c pixel color write ] each ] each ; inline
|
||||||
|
|
||||||
: ppm-header ( -- )
|
: ppm-header ( -- )
|
||||||
ascii encode-output
|
ascii encode-output
|
||||||
|
|
Loading…
Reference in New Issue