mandelbrot fractal

cvs
Slava Pestov 2004-08-27 00:10:25 +00:00
parent daadfa612c
commit 1dca03d0dc
1 changed files with 38 additions and 0 deletions

38
contrib/mandel.factor Normal file
View File

@ -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* ;