Skip to content

Instantly share code, notes, and snippets.

@yarbelk yarbelk/mandy.rb
Last active Aug 29, 2015

Embed
What would you like to do?
Mandelbrot Set done with colors (and BEN!)
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
@yarbelk

This comment has been minimized.

Copy link
Owner Author

commented Mar 20, 2015

Mandelbrot set

pass your escape radius as the first argument, or it will be 2.0

Done with @benjamintanweihao

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.