]> gitweb.factorcode.org Git - factor.git/commitdiff
mandelbrot fractal
authorSlava Pestov <slava@factorcode.org>
Fri, 27 Aug 2004 00:10:25 +0000 (00:10 +0000)
committerSlava Pestov <slava@factorcode.org>
Fri, 27 Aug 2004 00:10:25 +0000 (00:10 +0000)
contrib/mandel.factor [new file with mode: 0644]

diff --git a/contrib/mandel.factor b/contrib/mandel.factor
new file mode 100644 (file)
index 0000000..b73b031
--- /dev/null
@@ -0,0 +1,38 @@
+! Based on lisp code from newsgroup discussion in
+! comp.lang.lisp
+
+!  (loop for y from -1 to 1.1 by 0.1 do
+!        (loop for x from -2 to 1 by 0.04 do
+!              (let* ((c 126)
+!                     (z (complex x y))
+!                     (a z))
+!                (loop while (< (abs
+!                                (setq z (+ (* z z) a)))
+!                               2)
+!                  while (> (decf c) 32)) 
+!                (princ (code-char c))))
+!        (format t "~%"))
+
+USE: arithmetic
+USE: combinators
+USE: math
+USE: prettyprint
+USE: stack
+USE: stdio
+USE: strings
+
+: mandel-step ( a z c -- c )
+    >r dupd sq + dup abs 2 < [
+        r> pred dup CHAR: \s > [ mandel-step ] [ nip nip ] ifte
+    ] [
+        2drop r>
+    ] ifte ;
+
+: mandel-x ( x y -- )
+    rect> dup CHAR: ~ mandel-step >char write ;
+
+: mandel-y ( y -- )
+    75 [ dupd 25 / 2 - >float swap mandel-x ] times* drop terpri ;
+
+: mandel ( -- )
+    21 [ 10 / 1 - >float mandel-y ] times* ;