<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>crunchlife: Ruby Fractal Library 1.1.0</title>
    <link>http://crunchlife.com/articles/2008/10/24/ruby-fractal-library-1-1-0</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description></description>
    <item>
      <title>Ruby Fractal Library 1.1.0</title>
      <description>&lt;p&gt;&lt;img src="/files/feigenbaum.png" class="photo right"&gt;Between spending time with the baby and working on a new project (more to come), I&amp;#8217;ve found time to add a few features to the &lt;a href="http://crunchlife.com/pages/ruby_fractal_library"&gt;Ruby Fractal Library&lt;/a&gt;.  An Algorithms module now contains lambda expressions implementing both the &lt;a href="http://en.wikipedia.org/wiki/Mandelbrot_set#Escape_time_algorithm" target="_blank"&gt;Escape Time&lt;/a&gt; and &lt;a href="http://en.wikipedia.org/wiki/Mandelbrot_set#Continuous_.28smooth.29_coloring" target="_blank"&gt;Normalized Iteration Count&lt;/a&gt; algorithms.  Users can also create their own lambda expressions and assign them to the Fractal class&#8217;s algorithm property. &lt;/p&gt;

&lt;p&gt;In the example below, I&#8217;ve show the difference between images rendered using the Escape Time and Normalized Iteration Count algorithms.  As you can see, the Normalized Iteration Count algorithm generates images without the color banding associated with the Escape Time algorithm. &lt;/p&gt;

&lt;p&gt;&lt;center&gt;
  &lt;table cellpadding="5"&gt;
    &lt;tr&gt;
      &lt;td&gt;Escape Time&lt;/td&gt;
      &lt;td&gt;Normalized Iteration Count&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;
        &lt;img src="/files/mandelbrot_escape_time.png" class=&#8221;photo&#8221;&gt;
      &lt;/td&gt;
      &lt;td&gt;
        &lt;img src="/files/mandelbrot_normalized.png" class=&#8221;photo&#8221;&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/table&gt;
&lt;/center&gt;&lt;/p&gt;

&lt;p&gt;A Themes module now serves as a home for all of the library&amp;#8217;s predefined color palettes. There are only two, but they&amp;#8217;re easy to make. Since themes are also expressed as lambdas they too can be created by users and applied to the Fractal class. Below is my attempt at creating a snowflake using the Julia set and a user-defined theme.&lt;/p&gt;

&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;&lt;span class="ident"&gt;snowflakes&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="constant"&gt;Julia&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;new&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="constant"&gt;Complex&lt;/span&gt;&lt;span class="punct"&gt;(-&lt;/span&gt;&lt;span class="number"&gt;0.3007&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="number"&gt;0.6601&lt;/span&gt;&lt;span class="punct"&gt;),&lt;/span&gt; &lt;span class="number"&gt;5&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="number"&gt;100&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;
&lt;span class="ident"&gt;snowflakes&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;width&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="number"&gt;350&lt;/span&gt;
&lt;span class="ident"&gt;snowflakes&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;height&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="number"&gt;350&lt;/span&gt;
&lt;span class="ident"&gt;snowflakes&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;m&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="number"&gt;2&lt;/span&gt;
&lt;span class="ident"&gt;snowflakes&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;set_color&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="constant"&gt;PNG&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;Color&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;White&lt;/span&gt;
&lt;span class="ident"&gt;snowflakes&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;algorithm&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="constant"&gt;Algorithms&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;NormalizedIterationCount&lt;/span&gt;
&lt;span class="ident"&gt;snowflakes&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;theme&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="ident"&gt;lambda&lt;/span&gt; &lt;span class="punct"&gt;{&lt;/span&gt; &lt;span class="punct"&gt;|&lt;/span&gt;&lt;span class="ident"&gt;index&lt;/span&gt;&lt;span class="punct"&gt;|&lt;/span&gt;
  &lt;span class="ident"&gt;r&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="ident"&gt;g&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="ident"&gt;b&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="number"&gt;0&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="number"&gt;0&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="number"&gt;0&lt;/span&gt;      
  &lt;span class="keyword"&gt;if&lt;/span&gt; &lt;span class="ident"&gt;index&lt;/span&gt; &lt;span class="punct"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="number"&gt;510&lt;/span&gt;
    &lt;span class="ident"&gt;r&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="number"&gt;0&lt;/span&gt;
    &lt;span class="ident"&gt;g&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="number"&gt;255&lt;/span&gt; &lt;span class="punct"&gt;%&lt;/span&gt; &lt;span class="ident"&gt;index&lt;/span&gt;
    &lt;span class="ident"&gt;b&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="number"&gt;255&lt;/span&gt;
  &lt;span class="keyword"&gt;elsif&lt;/span&gt; &lt;span class="ident"&gt;index&lt;/span&gt; &lt;span class="punct"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="number"&gt;255&lt;/span&gt;
    &lt;span class="ident"&gt;r&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="number"&gt;0&lt;/span&gt;
    &lt;span class="ident"&gt;g&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="ident"&gt;index&lt;/span&gt; &lt;span class="punct"&gt;%&lt;/span&gt; &lt;span class="number"&gt;255&lt;/span&gt;
    &lt;span class="ident"&gt;b&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="number"&gt;255&lt;/span&gt;
  &lt;span class="keyword"&gt;else&lt;/span&gt;    
    &lt;span class="ident"&gt;b&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="ident"&gt;index&lt;/span&gt; &lt;span class="punct"&gt;%&lt;/span&gt; &lt;span class="number"&gt;255&lt;/span&gt;
  &lt;span class="keyword"&gt;end&lt;/span&gt;      
  &lt;span class="keyword"&gt;return&lt;/span&gt; &lt;span class="ident"&gt;r&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="ident"&gt;g&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="ident"&gt;b&lt;/span&gt;
&lt;span class="punct"&gt;}&lt;/span&gt;
&lt;span class="ident"&gt;snowflakes&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;draw&lt;/span&gt;&lt;span class="punct"&gt;('&lt;/span&gt;&lt;span class="string"&gt;snowflakes.png&lt;/span&gt;&lt;span class="punct"&gt;')&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Snowflakes was inspired by a colleague who wondered why I kept creating paisley.  The Fire theme will do that. :)&lt;/p&gt;

&lt;p&gt;&lt;center&gt;
&lt;img src="/files/snowflakes.png" class="photo"&gt;
&lt;/center&gt;
&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;When I get more time I&#8217;d like to implement some of the Escape Angle and Curvature Estimation algorithms as &lt;a href="http://math.unipa.it/~grim/Jbarrallo.PDF" target="_blank"&gt;outlined by Garcia, Fernandez, Barrallo, and Martin&lt;/a&gt;, but for now I&#8217;d gladly accept any user-contributed algorithms or themes. &lt;/p&gt;

&lt;p&gt;A fractal can now be instantiated with a single point rather than a range.  This is the biggest breaking change over version 1.0.0.  I believe that this makes the library easier to use and more similar to other fractal generating programs.  The Fractal type also contains a where_is? method.  This should help when trying to determine the complex coordinate of an x, y value pair.&lt;/p&gt;

&lt;p&gt;In testing the library, I attempted to generate a few of the fractals found in the &lt;a href="http://en.wikipedia.org/wiki/Mandelbrot_set" target="_blank"&gt;Mandelbrot set Wikipedia entry&lt;/a&gt;. The images found at Wikipedia were rendered using Ultra Fractal 3 and are beautiful.  Knowing Ruby, I didn&#8217;t expect to generate images with the same quality, but I was pleasantly surprised.  Here is &amp;#8220;Satellite&amp;#8221; followed by the Misiurewicz point.  Both were rendered with the &lt;a href="http://crunchlife.com/pages/ruby_fractal_library"&gt;Ruby Fractal Library&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;center&gt;&lt;/p&gt;

&lt;table cellpadding="5"&gt;
    &lt;tr&gt;
      &lt;td&gt;Satellite&lt;/td&gt;
      &lt;td&gt;Misiurewicz point&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;
        &lt;img src="/files/satellite.png" class=&#8221;photo&#8221;&gt;
      &lt;/td&gt;
      &lt;td&gt;
        &lt;img src="/files/misiurewicz.png" class=&#8221;photo&#8221;&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/table&gt;

&lt;p&gt;&lt;/center&gt;
&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;Satellite can be found where c = -0.743643135, 0.131825963i at around 200k magnification. I had to set max_iterations = 1500 to get this level of detail.  It still took a few minutes to render using the latest YARV interpreter on an Intel Core 2 Duo 2.6Ghz.  Overall I&#8217;ve noticed that YARV finishes rendering the Mandelbrot set in approximately half the time of the old Matz interpreter. Not a bad gain.  It&#8217;ll never be as quick as C, but I still look forward to Ruby 2.0!&lt;/p&gt;

&lt;p&gt;The &lt;a href="http://crunchlife.com/pages/ruby_fractal_library"&gt;Ruby Fractal Library&lt;/a&gt; can be found under the &amp;#8220;Projects&amp;#8221; section of this website.  Feel free to send me any feedback.  I&#8217;d love to see some new color themes or algorithms.&lt;/p&gt;</description>
      <pubDate>Fri, 24 Oct 2008 11:49:00 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:6dfbe339-553c-42c6-b854-6cae91137aed</guid>
      <author>Ryan Baxter</author>
      <link>http://crunchlife.com/articles/2008/10/24/ruby-fractal-library-1-1-0</link>
      <category>Code Snippets</category>
      <category>Fractals</category>
      <category>Ruby</category>
      <enclosure type="image/png" length="108876" url="http://crunchlife.com/files/satellite.png"/>
      <trackback:ping>http://crunchlife.com/articles/trackback/83</trackback:ping>
    </item>
    <item>
      <title>"Ruby Fractal Library 1.1.0" by Ryan Baxter</title>
      <description>Thanks! I use either Ubuntu or Cygwin with GCC to handle the RubyInline requirements of the PNG library. My reasons for choosing PNG over RMagick were purely subjective. IMO PNG is much easier to use and, in my case, install. I've thought about using RMagick in the future to allow images to be saved as other file types. I'll contact ya via e-mail.&lt;br /&gt;&lt;br /&gt;

If any Windows users need a C compiler, I suggest using Cygwin with GCC. GCC is great and free!&lt;br /&gt;&lt;br /&gt;

If more people are interested in contributing I'll set up some sort of project management software.</description>
      <pubDate>Tue, 04 Nov 2008 12:25:40 -0800</pubDate>
      <guid isPermaLink="false">urn:uuid:8bc9363e-3ce3-4374-b26d-816327693526</guid>
      <link>http://crunchlife.com/articles/2008/10/24/ruby-fractal-library-1-1-0#comment-8339</link>
    </item>
    <item>
      <title>"Ruby Fractal Library 1.1.0" by Brian </title>
      <description>Nice work on your fractals. I've tried to run your code but hit a wall getting png.rb to work due to the inline requirement. What C compiler did you install to get inline to work? I'm thinking about hacking your code to work with ImageMagick instead of png.rb. Any thoughts? You can email me at caneridge at gmail dot com.

Brian
Roseville California</description>
      <pubDate>Tue, 04 Nov 2008 12:16:43 -0800</pubDate>
      <guid isPermaLink="false">urn:uuid:3127bbfd-7d3f-4315-802a-0eb24dbd087d</guid>
      <link>http://crunchlife.com/articles/2008/10/24/ruby-fractal-library-1-1-0#comment-8338</link>
    </item>
  </channel>
</rss>
