<?xml version="1.0" encoding="UTF-8" ?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc=" http://purl.org/dc/elements/1.1/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>briancarper.net Tag: Mandelbrot</title><link>http://briancarper.net/tag/mandelbrot</link><description>Some guy's blog about programming and Linux and cows</description><item><title>More Clojure Mandelbrot Goodness</title><link>http://briancarper.net/blog/more-clojure-mandelbrot-goodness</link><guid>http://briancarper.net/blog/more-clojure-mandelbrot-goodness</guid><pubDate>Wed, 20 May 2009 23:39:23 -0700</pubDate><description>&lt;p&gt;After my &lt;a href=&quot;http://briancarper.net/clojure/mandelbrot-swing.clj&quot;&gt;brief stint&lt;/a&gt; in the world of fractal geometry and Clojure, I decided to make a real Mandelbrot set viewer.  The resulting source code is &lt;a href=&quot;http://briancarper.net/clojure/mandelbrot-swing.clj&quot;&gt;here&lt;/a&gt;.  Here's a simple output (click for bigger version):&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://briancarper.net/clojure/mandelbrot/mandelbrot-smooth.png&quot;&gt; &lt;img src=&quot;/clojure/mandelbrot/thumbs/mandelbrot-smooth.png&quot; alt=&quot;/clojure/mandelbrot/thumbs/mandelbrot-smooth.png&quot; title=&quot;&quot; /&gt; &lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It's a pretty naive implementation, barely 100 lines of code, but even with my brute-force approach, given a liberal sprinkling of type hints it runs fast enough.  Programming Swing from Clojure couldn't be easier (though I doubt programming Swing from any language is ever really enjoyable, it's a painful bunch of libraries).&lt;/p&gt;

&lt;p&gt;There's a discussion of &lt;a href=&quot;http://en.wikipedia.org/wiki/Mandelbrot_set#For_programmers&quot;&gt;different coloring algorithms&lt;/a&gt; on Wikipedia, but even after reading that, getting this thing to look good was difficult.  I don't know enough math for it.  I ended up cheating and I colored a couple of them in the GIMP, so I could use them as desktop wallpapers.  &lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://briancarper.net/clojure/mandelbrot/mandelbrot-rainbow.png&quot;&gt; &lt;img src=&quot;/clojure/mandelbrot/thumbs/mandelbrot-rainbow.png&quot; alt=&quot;/clojure/mandelbrot/thumbs/mandelbrot-rainbow.png&quot; title=&quot;&quot; /&gt; &lt;/a&gt; 
&lt;a href=&quot;http://briancarper.net/clojure/mandelbrot/mandelbrot-rainbow-2.png&quot;&gt; &lt;img src=&quot;/clojure/mandelbrot/thumbs/mandelbrot-rainbow-2.png&quot; alt=&quot;/clojure/mandelbrot/thumbs/mandelbrot-rainbow-2.png&quot; title=&quot;&quot; /&gt; &lt;/a&gt;  &lt;a href=&quot;http://briancarper.net/clojure/mandelbrot/mandelbrot-rainbow-3.png&quot;&gt; &lt;img src=&quot;/clojure/mandelbrot/thumbs/mandelbrot-rainbow-3.png&quot; alt=&quot;/clojure/mandelbrot/thumbs/mandelbrot-rainbow-3.png&quot; title=&quot;&quot; /&gt; &lt;/a&gt;  &lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://briancarper.net/clojure/mandelbrot/mandelbrot-rainbow-4.png&quot;&gt; &lt;img src=&quot;/clojure/mandelbrot/thumbs/mandelbrot-rainbow-4.png&quot; alt=&quot;/clojure/mandelbrot/thumbs/mandelbrot-rainbow-4.png&quot; title=&quot;&quot; /&gt; &lt;/a&gt; &lt;a href=&quot;http://briancarper.net/clojure/mandelbrot/mandelbrot-rainbow-5.png&quot;&gt; &lt;img src=&quot;/clojure/mandelbrot/thumbs/mandelbrot-rainbow-5.png&quot; alt=&quot;/clojure/mandelbrot/thumbs/mandelbrot-rainbow-5.png&quot; title=&quot;&quot; /&gt; &lt;/a&gt; &lt;/p&gt;

&lt;p&gt;There are some more PNGS &lt;a href=&quot;http://briancarper.net/page/clojure&quot;&gt;over here&lt;/a&gt; including one that's 16000x16000 (producing it almost melted my CPU last night).&lt;/p&gt;</description></item><item><title>Clojure: ASCII Mandelbrot Set</title><link>http://briancarper.net/blog/clojure-ascii-mandelbrot-set</link><guid>http://briancarper.net/blog/clojure-ascii-mandelbrot-set</guid><pubDate>Tue, 12 May 2009 18:46:01 -0700</pubDate><description>&lt;p&gt;Did you know there's this neat &lt;a href=&quot;http://www.lispforum.com/index.php&quot;&gt;Lisp message board&lt;/a&gt; where from time to time someone posts a &lt;a href=&quot;http://www.lispforum.com/viewtopic.php?f=32&amp;amp;t=334&quot;&gt;short problem&lt;/a&gt; similar in spirit to the infamous &lt;a href=&quot;http://www.rubyquiz.com/&quot;&gt;RubyQuiz&lt;/a&gt;?&lt;/p&gt;

&lt;p&gt;Not a lot of people have participated so far, hopefully that changes.  I participated this time; the problem is to render the Mandelbrot Set in ASCII. Here's my &lt;a href=&quot;http://briancarper.net/clojure/mandelbrot.clj&quot;&gt;Clojure version&lt;/a&gt; (based loosely on &lt;a href=&quot;http://bc.tech.coop/blog/040811.html&quot;&gt;this one&lt;/a&gt;).&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;(ns mandelbrot
  (:refer-clojure :exclude [+ * &amp;lt;])
  (:use (clojure.contrib complex-numbers)
        (clojure.contrib.generic [arithmetic :only [+ *]]
                                 [comparison :only [&amp;lt;]]
                                 [math-functions :only [abs]])))

(defn- mandelbrot-seq [x y]
  (let [z (complex x y)]
    (iterate #(+ z (* % %)) z)))

(defn- mandelbrot-char [x y]
  (loop [c 126
         m (mandelbrot-seq x y)]
    (if (and (&amp;lt; (abs (first m)) 2)
             (&amp;gt; c 32))
      (recur (dec c) (rest m))
      (char c))))

(defn- mandelbrot-line [xs y]
  (apply str (map #(mandelbrot-char % y) xs)))

(defn- m-range [min max num-steps]
  (range min
         max
         (/ (+ (abs min)
               (abs max))
            num-steps)))

(defn mandelbrot [rmin rmax imin imax]
  (let [rows 30
        cols 50
        xs (m-range rmin rmax cols)
        ys (m-range imin imax rows)]
    (dorun (map #(println (mandelbrot-line xs %)) ys))))

(comment
  ;Example run:
  (mandelbrot -2.0 1.0 -1.5 1.5)
&quot;
~~~~~~~~~~~~}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
~~~~~~~~~~~~}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
~~~~~~~~~~}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
~~~~~~~~~}}}}}}}}}}}}|||||||||}}}}}}}}}}}}}}}}}}}}
~~~~~~~}}}}}}}}|||||||||||||||||||||}}}}}}}}}}}}}}
~~~~~~}}}}}||||||||||||||{{{{zlxz{{{||||}}}}}}}}}}
~~~~~}}}}|||||||||||||{{{{{zzyxpvlz{{{||||}}}}}}}}
~~~~}}}|||||||||||||{{{{{{zzyxvnpwyzz{{{||||}}}}}}
~~~}}|||||||||||||{{{{{{zzyyws   .vyzzz{{|||||}}}}
~~~}||||||||||||{{{{{zzxwwwvus   muvxyywz{|||||}}}
~~}|||||||||||{{{zzzzyyu= p         oteqpz{|||||}}
~~||||||||||{zzzzzzyyyvtm              oxz{{|||||}
~}|||||{{{zyvwxxxxxxxwrG                vuz{|||||}
~||{{{{{zzzywsMsqRovvs                  pxz{{|||||
~|{{{{{zzzyxsq      pj                  `xz{{|||||
~{{{{yyyxwsrp                           wyz{{|||||
~?:3 3 #                              ovxzz{{|||||
~{{{{yyyxwsrp                           wyz{{|||||
~|{{{{{zzzyxsq      pj                  `xz{{|||||
~||{{{{{zzzywsMsqRovvs                  pxz{{|||||
~}|||||{{{zyvwxxxxxxxwrG                vuz{|||||}
~~||||||||||{zzzzzzyyyvtm              oxz{{|||||}
~~}|||||||||||{{{zzzzyyu= p         oteqpz{|||||}}
~~~}||||||||||||{{{{{zzxwwwvus   muvxyywz{|||||}}}
~~~}}|||||||||||||{{{{{{zzyyws   .vyzzz{{|||||}}}}
~~~~}}}|||||||||||||{{{{{{zzyxvnpwyzz{{{||||}}}}}}
~~~~~}}}}|||||||||||||{{{{{zzyxpvlz{{{||||}}}}}}}}
~~~~~~}}}}}||||||||||||||{{{{zlxz{{{||||}}}}}}}}}}
~~~~~~~}}}}}}}}|||||||||||||||||||||}}}}}}}}}}}}}}
~~~~~~~~~}}}}}}}}}}}}|||||||||}}}}}}}}}}}}}}}}}}}}
~~~~~~~~~~}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
&quot;
)
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And here's some &lt;a href=&quot;http://www.youtube.com/watch?v=ES-yKOYaXq0&quot;&gt;obligatory Jonathan Coulton&lt;/a&gt;.&lt;/p&gt;</description></item></channel></rss>
