One Year and Counting
Posted by Ryan Baxter Fri, 11 Jul 2008 22:05:00 GMT
July marks the one year anniversary of this website. I didn’t think
I’d keep up with it this long, but throughout the past year,
crunchlife.com has become a springboard for ideas and a wonderful source of reference. Just as other programmers, I have found that maintaining a blog helps crystallize my thoughts. It also has the added benefit of documenting my fixes and failures for not only myself, but the rest of the community. It has been very gratifying reading everyone’s comments. Keep them coming.
While reminiscing, I thought I’d list my top five most viewed posts.
- Review: Linksys NAS200 - By and far the most popular post on crunchlife.com. This article has accounted for over 70% of my web traffic from July 2007 to July 2008. I had no idea it would become that popular and if I could duplicate its success on a daily basis I might consider quitting my day job. Not really.
- IE7’s Inanimate GIF - Explains how to reanimate hidden animated GIFs in IE7 with a little JavaScript.
- Samba Network Shares with Nautilus in Hardy Heron Part 2 - This time I posted a solution to a problem I was having in mounting SMB shares on my NAS200 using Nautilus in Ubuntu, Hardy Heron. The solution worked well and I’ll be posting a follow-up soon.
- rake aborted! No such file or directory - /tmp/mysql.sock - Provides a fix for the much hated “rake aborted! No such file or directory - /tmp/mysql.sock” Ruby on Rails error.
- Temporary Identity Impersonation in ASP.NET - If you’d rather only use ASP.NET Identity Impersonation when you want to then this article can explain how it’s done.
Many projects in the 9-to-5 grind of a programmer seem endless and are not gratifying in the least. Seeking fulfillment, developers often work on side projects. I have found this to be an extremely rewarding way to satisfy my inner programmer and push my career in new directions. So without a doubt, my favorite posts have to do with the stuff we all love – source code.
- Ruby Fractal Library - Just last week I posted a fractal generating library for the Ruby programming language. I’m rather proud of this one. The “zooming” functionality caused a lot of grief, but once it starting rendering the Mandelbrot set all became right with the world.
- Samba Network Shares with Nautilus in Hardy Heron Part 2 - Most old *nix salts will tell you that any problem can be solved with a Bash script. They are right. This script improved my WAF (Wife Acceptance Factor) tenfold!
- Genealogy Data for the Future - Not exactly source code, but solving problems with a few small tools can feel nearly as good.
The last twelve months have been great and I’m sure the next will be even better.
- Meta no trackbacks, 1 comment, permalink, rss, atom
Ruby Fractal Library
Posted by Ryan Baxter Thu, 03 Jul 2008 21:26:00 GMT
*Update: Version 1.1.0 of the Ruby Fractal Library has been released.
Last October, I wrote a small fractal rendering program in Ruby using the Shoes windowing toolkit written by why the lucky stiff. It’s sole purpose was to test Shoes. The code was painfully slow at rendering the Mandelbrot set, but it did, however, begin a small obsession of mine with fractals.
Since I couldn’t find a fractal library for Ruby, I decided to write one. Over the last two weeks I’ve written some code to generate both the Mandelbrot and Julia set fractals using the escape time algorithm. The code is still slow, but within a couple weeks I hope to replace the slow portions with inline C.
There may still be some bugs and I haven’t added any error handling, but here it is. An “almost” pure Ruby fractal library. Once this is cleaned up I’ll repost the code. I suppose a gem could be possible as well. Happy 4th!
# RB
require 'rubygems'
require 'complex'
require 'png'
module Fractals
module Fractal
attr_accessor :begin_range, :end_range
def initialize(begin_range, end_range)
@begin_range, @end_range = begin_range, end_range
end
def draw(height=250, width=250, m=1.0, save_as='fractal.png')
canvas = PNG::Canvas.new(height, width)
# Find the complex coordinate for each pixel.
0.upto(height - 1) { |y|
i = (y * (@end_range.image - @begin_range.image) / height +
@begin_range.image) * m
0.upto(width - 1) { |x|
r = (x * (@end_range.real - @begin_range.real) / width +
@begin_range.real) * m
if self.in_set?(Complex(r, i)) then
canvas[x, y] = PNG::Color::Black
else
canvas[x, y] = fetch_color(self.last_iteration, self.max_iterations)
end
}
}
png = PNG.new(canvas)
png.save(save_as)
end
private
def fetch_color(last_iteration, max_iterations)
divisor = 765*last_iteration/max_iterations
case divisor
when 0..254 then return PNG::Color.new(divisor%255, 0, 0, 255)
when 255..509 then return PNG::Color.new(255, divisor%255, 0, 255)
when 510..765 then return PNG::Color.new(255, 255, divisor%255, 255)
end
end
end
class Julia
include Fractal
attr_accessor :seed, :bailout, :max_iterations
attr_reader :last_iteration
def initialize(seed=Complex(0.36, 0.1), bailout=2, max_iterations=100,
begin_range=Complex(-2.25, -1.5), end_range=Complex(0.75, 1.5))
super(begin_range, end_range)
@seed, @bailout, @max_iterations = seed, bailout, max_iterations
end
def in_set?(z)
@max_iterations.times { |i|
z = z**2 + @seed
if z > @bailout then
@last_iteration = i
return false
end
}
return true
end
end
class Mandelbrot
include Fractal
attr_accessor :bailout, :max_iterations
attr_reader :last_iteration
def initialize(bailout=5, max_iterations=100, begin_range=Complex(-2.25,
-1.5), end_range=Complex(0.75, 1.5))
super(begin_range, end_range)
@bailout, @max_iterations = bailout, max_iterations
end
def in_set?(c)
z = 0
@max_iterations.times { |i|
z = z**2 + c
if z > @bailout then
@last_iteration = i
return false
end
}
return true
end
end
endUsing this library is as simple as the following:
require 'fractals'
mandelbrot = Fractals::Mandelbrot.new
mandelbrot.drawAny suggestions/bug fixes can be posted here. Thanks.
- Posted in Code Snippets
- Meta no trackbacks, 3 comments, permalink, rss, atom
Older posts: 1 2

