Ruby Fractal Library and RMagick?

Posted by Ryan Baxter Tue, 11 Nov 2008 20:06:00 GMT

Sure, why not! Thanks to Brian Jones, the Ruby Fractal Library now renders fractals with RMagick. Images can be saved in formats including, PNG, GIF, JPEG, and many others. I was able to create an animated GIF displaying the magnification of the Feigenbaum point in less than 15 lines of code.

feigenbaum = Mandelbrot.new(Complex(-0.1528, 1.0397), 2, 100)
feigenbaum.width = 150
feigenbaum.height = 150
feigenbaum.m = 25
feigenbaum.algorithm = Algorithms::NormalizedIterationCount
feigenbaum.theme = Themes::Water

image_list = Magick::ImageList.new
image_list.delay = 100
image_list.iterations = 1

(0...50).each { |i|
  feigenbaum.m += (i**2)
  image_list << Magick::Image.from_blob(feigenbaum.draw('gif'))[0]
}

image_list.write('feigenbaum.gif')


The recent changes have caused a couple of breaking changes. Now that RMagick is used, ImageMagick must be installed as a dependency. I was against this at first, but RMagick’s flexibility ultimately won me over (I couldn’t resist the lure of animated fractals). The Fractal.draw method now returns an image as a BLOB, but a save_as method has been provided to handle the writing of images to disk. The curious can find that latest source code in the repo’s trunk. Stay tuned for more updates.

svn checkout -r 10 http://svn.ryanbaxter.net/fractals/trunk fractals

As always, I’ll accept any comments, suggestions, or source code. Thanks again to Brian for the RMagick submission.

Trackbacks

Use the following link to trackback from your own site:
http://crunchlife.com/articles/trackback/86

Comments

Leave a response