]> gitweb.factorcode.org Git - factor.git/commitdiff
Clean up mandelbrot
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Wed, 10 Sep 2008 23:22:50 +0000 (18:22 -0500)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Wed, 10 Sep 2008 23:22:50 +0000 (18:22 -0500)
extra/benchmark/mandel/colors/colors.factor
extra/benchmark/mandel/mandel.factor
extra/benchmark/mandel/params/params.factor

index 848fbae01e2deddcf5ae4a7b033c6488b68f98f2..7bbb25a47d532a5be1c16628610b2524cd54592a 100644 (file)
@@ -16,4 +16,4 @@ IN: benchmark.mandel.colors
     ] with map ;
 
 : color-map ( -- map )
-    nb-iter max-color min <color-map> ; foldable
+    max-iterations max-color min <color-map> ; foldable
index a40b123ed302656cce27756f0b5ee59540d9dd4e..e87765499b629a662b46f27aeb6487d4be78e821 100755 (executable)
@@ -1,16 +1,11 @@
+! Copyright (C) 2005, 2008 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
 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
+math.parser sequences byte-arrays byte-vectors io.files
+io.encodings.binary fry namespaces benchmark.mandel.params
 benchmark.mandel.colors ;
 IN: benchmark.mandel
 
-: iter ( c z nb-iter -- x )
-    dup 0 <= [ 2nip ] [
-        over absq 4.0 >= [ 2nip ] [
-            >r sq dupd + r> 1- iter
-        ] if
-    ] if ; inline recursive
-
 : x-inc width  200000 zoom-fact * / ; inline
 : y-inc height 150000 zoom-fact * / ; inline
 
@@ -19,27 +14,27 @@ IN: benchmark.mandel
     [ y-inc * center imaginary-part y-inc height 2 / * - + >float ] bi*
     rect> ; inline
 
-:: render ( accum -- )
-    height [
-        width swap [
-            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
-        ] curry each
-    ] each ; inline
-
-:: 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
+: 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
+    '[ sq , + ] [ absq 4.0 >= ] count-iterations ; inline
+
+: color ( iterations -- color )
+    [ color-map [ length mod ] keep nth ] [ B{ 0 0 0 } ] if* ; inline
+
+: render ( -- )
+    height [ width swap '[ , c pixel color % ] each ] each ; inline
+
+: ppm-header ( -- )
+    "P6\n" % width # " " % height # "\n255\n" % ; inline
 
 : buf-size ( -- n ) width height * 3 * 100 + ; inline
 
 : mandel ( -- data )
     buf-size <byte-vector>
-    [ ppm-header ] [ render ] [ B{ } like ] tri ;
+    [ building [ ppm-header render ] with-variable ] [ B{ } like ] bi ;
 
 : mandel-main ( -- )
     mandel "mandel.ppm" temp-file binary set-file-contents ;
index 3fcfe1d3ef6462fdf4b7be4803817866b6055f59..c40d3c1f2d009863cad01c9139705ee5207b22c3 100644 (file)
@@ -1,8 +1,8 @@
 IN: benchmark.mandel.params
 
-: max-color 360   ; inline
-: zoom-fact 0.8   ; inline
-: width     640   ; inline
-: height    480   ; inline
-: nb-iter   40    ; inline
-: center    -0.65 ; inline
+: max-color       360   ; inline
+: zoom-fact       0.8   ; inline
+: width           640   ; inline
+: height          480   ; inline
+: max-iterations  40    ; inline
+: center         -0.65  ; inline