Skip to content

Instantly share code, notes, and snippets.

@DylanFM
Created May 28, 2009 10:27
Show Gist options
  • Select an option

  • Save DylanFM/119211 to your computer and use it in GitHub Desktop.

Select an option

Save DylanFM/119211 to your computer and use it in GitHub Desktop.
# http://www.xcombinator.com/2008/02/22/ruby-inject-and-the-mandelbrot-set/
require 'complex'
def mandelbrot(a)
Array.new(50,a).inject(a) { |z,c| z*z + c }
end
(1.0).step(-1,-0.05) do |y|
(-2.0).step(0.5,0.0315) do |x|
print mandelbrot(Complex(x,y)).abs < 2 ? '*' : ' '
end
puts
end
# >>
# >>
# >>
# >> **
# >> ******
# >> ********
# >> ******
# >> ******** ** *
# >> *** *****************
# >> ************************ ***
# >> ****************************
# >> ******************************
# >> ******************************
# >> ************************************
# >> * **********************************
# >> ** ***** * **********************************
# >> *********** ************************************
# >> ************** ************************************
# >> ***************************************************
# >> *****************************************************
# >> ***********************************************************************
# >> *****************************************************
# >> ***************************************************
# >> ************** ************************************
# >> *********** ************************************
# >> ** ***** * **********************************
# >> * **********************************
# >> ************************************
# >> ******************************
# >> ******************************
# >> ****************************
# >> ************************ ***
# >> *** *****************
# >> ******** ** *
# >> ******
# >> ********
# >> ******
# >> **
# >>
# >>
# >>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment