benchmark.mandel: clean up the code a bit without changing performance

- use iota when iterating over integers
- clean up 'c' word
db4
Slava Pestov 2009-09-24 02:51:43 -05:00
parent dee151432c
commit 1813896d14
2 changed files with 11 additions and 12 deletions

View File

@ -1,5 +1,5 @@
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
: scale ( x -- y ) 255 * >fixnum ; inline
@ -11,10 +11,10 @@ CONSTANT: sat 0.85
CONSTANT: val 0.85
: <color-map> ( nb-cols -- map )
dup [
360 * swap 1 + / sat val
[ iota ] keep '[
360 * _ 1 + / sat val
1 <hsva> >rgba scale-rgb
] with map ;
] map ;
: color-map ( -- map )
max-iterations max-color min <color-map> ; foldable

View File

@ -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.
USING: io kernel math math.functions sequences prettyprint
io.files io.files.temp io.encodings io.encodings.ascii
@ -6,13 +6,12 @@ io.encodings.binary fry benchmark.mandel.params
benchmark.mandel.colors ;
IN: benchmark.mandel
: x-inc ( -- x ) width 200000 zoom-fact * / ; inline
: y-inc ( -- y ) height 150000 zoom-fact * / ; inline
: x-scale ( -- x ) width 200000 zoom-fact * / ; inline
: y-scale ( -- y ) height 150000 zoom-fact * / ; inline
: c ( i j -- c )
[ x-inc * center real-part x-inc width 2 / * - + >float ]
[ y-inc * center imaginary-part y-inc height 2 / * - + >float ] bi*
rect> ; inline
: scale ( x y -- z ) [ x-scale * ] [ y-scale * ] bi* rect> ; inline
: c ( i j -- c ) scale center width height scale 2 / - + ; inline
: count-iterations ( z max-iterations step-quot test-quot -- #iters )
'[ 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
: 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 ( -- )
ascii encode-output