Paste number 51002: mandelbrot

Paste number 51002: mandelbrot
Pasted by: jmbr
9 months, 1 week ago
#lispcafe | Context in IRC logs
Paste contents:
Raw Source | XML | Display As
;;; 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.

Colorize as:
Show Line Numbers

Ads absolutely not by Google

Lisppaste pastes can be made by anyone at any time. Imagine a fearsomely comprehensive disclaimer of liability. Now fear, comprehensively.