Skip to content

Instantly share code, notes, and snippets.

View gist:1333743
(defn text-mandel [size a b limit]
(let [[w _ ms] (mandelbrot-seqs 1 size a b limit)
[_ _ _ _ m] (first ms)
s (map (fn [[_ _ i]]
(if (zero? i) " " (str (int (* 9 (/ i limit)))))) m)]
(println
(interpose \newline
(map #(apply str %)
(partition w s))))))
View gist:1333693
(defn- ranges [l s]
(partition 2 1 [l] (range 0 l s)))
View gist:1333629
(defn- mandelbrot-seqs [n size a b limit]
(let [[lower upper] (normalize a b)
d (delta size lower upper)
[w h] (dimensions size lower upper)]
[w h
(for [[ly uy] (ranges h (int (/ h (min n h))))]
[ 0 ly w (- uy ly) (mandelbrot-seq (range 0 w) (range ly uy) lower d limit) ]
)]))
View gist:1333587
(defn- mandelbrot-seq [x-range y-range [lr li] d limit]
(for [y y-range :let [i (+ li (* y d))]
x x-range :let [r (+ lr (* x d))]]
[x y (mandelbrot r i limit)]))
View gist:1333551
(defn mandelbrot [c ^long limit]
(loop [rate limit
s (iterate #(+ (* % %) c) 0.0)]
(if (and (> rate 0) (< (abs (first s)) 2.0))
(recur (dec rate) (rest s))
rate)))
View gist:1333534
(defn mandelbrot [^double cr ^double ci ^long limit]
(loop [rate limit
zr 0.0
zi 0.0]
(let [zr2 (* zr zr)
zi2 (* zi zi)]
(if (and (> rate 0) (< (+ zr2 zi2) 4.0))
(recur (dec rate) (+ cr (- zr2 zi2)) (+ ci (* 2.0 (* zr zi))) )
rate))))