factor/contrib/mandel.factor

41 lines
993 B
Factor
Raw Normal View History

2004-08-26 20:10:25 -04:00
! 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: combinators
USE: math
USE: prettyprint
USE: stack
USE: stdio
USE: strings
2004-08-26 20:13:44 -04:00
: ?mandel-step ( a z c -- a z c ? )
2004-08-26 20:10:25 -04:00
>r dupd sq + dup abs 2 < [
2004-08-26 20:13:44 -04:00
r> pred dup CHAR: \s >
2004-08-26 20:10:25 -04:00
] [
2004-08-26 20:13:44 -04:00
r> f
2004-08-26 20:10:25 -04:00
] ifte ;
2004-08-26 23:11:46 -04:00
: mandel-step ( a z c -- )
[ ?mandel-step ] [ ] while >char write 2drop ;
2004-08-26 20:13:44 -04:00
2004-08-26 20:10:25 -04:00
: mandel-x ( x y -- )
2004-08-26 23:11:46 -04:00
rect> dup CHAR: ~ mandel-step ;
2004-08-26 20:10:25 -04:00
: mandel-y ( y -- )
2004-09-26 20:16:02 -04:00
150 [ dupd 50 / 2 - >float swap mandel-x ] times* drop ;
2004-08-26 20:10:25 -04:00
: mandel ( -- )
2004-09-26 20:16:02 -04:00
42 [ 20 / 1 - >float mandel-y terpri ] times* ;