Last active
August 29, 2015 14:17
-
-
Save yarbelk/e72e216fdad1a043c302 to your computer and use it in GitHub Desktop.
Mandelbrot Set done with colors (and BEN!)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'complex' | |
XR = 0.01575 * 2 | |
YR = 0.0125 * 2 | |
ESCAPE_RADIUS = ARGV[0].to_f || 2.0 | |
def mandelbrot(a) | |
x = a.real | |
y = a.imaginary | |
i = 0 | |
Array.new(512,a).inject(a) do |z,c| | |
i += 1 | |
result = z*z + c | |
break result if result.abs > ESCAPE_RADIUS | |
result | |
end | |
return Math.log2(i) | |
end | |
COLORS = [ | |
"\033[31m", | |
"\033[32m", | |
"\033[33m", | |
"\033[34m", | |
"\033[35m", | |
"\033[36m", | |
"\033[37m", | |
"\033[1;30m", | |
"\033[1;31m", | |
"\033[1;32m" | |
] | |
def print_mandy c | |
print COLORS[c.to_i] + c.to_i.to_s + "\033[0m" | |
end | |
(1.0).step(-1.0,-0.5*YR) do |y| | |
(-2.0).step(0.5,0.5*XR) do |x| | |
print_mandy mandelbrot(Complex(x,y)) | |
end | |
puts | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Mandelbrot set
pass your escape radius as the first argument, or it will be 2.0
Done with @benjamintanweihao