| Paste number 51002: | mandelbrot |
| Pasted by: | jmbr |
| 9 months, 1 week ago | |
| #lispcafe | Context in IRC logs | |
| Paste contents: |
| ;;; Translated from: ;;; http://blogs.msdn.com/lukeh/archive/2007/11/14/f.aspx (defconstant +max-iteration+ 100) (defun mod-squared (c) (expt (abs c) 2)) (define-condition escaped () ((n :type fixnum))) (define-condition did-not-escape () ()) (defun mandelbrot (c) (labels ((mandelbrot-inner (z iterations) (cond ((>= (mod-squared z) 4) (signal 'escaped iterations)) ((= iterations +max-iteration+) (signal 'did-not-escape)) (t (mandelbrot-inner (+ (* z z) c) (1+ iterations)))))) (mandelbrot-inner c 0))) (loop for y from -1 to 1 by 0.1 do (loop for x from -2 to 1 by 0.05 do (handler-case (mandelbrot (complex x y)) (did-not-escape () (format t "#")) (escaped (n) (format t " ")))) (format t "~%")) |
This paste has no annotations.