Skip to content

Instantly share code, notes, and snippets.

@yarbelk
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yarbelk/e72e216fdad1a043c302 to your computer and use it in GitHub Desktop.
Save yarbelk/e72e216fdad1a043c302 to your computer and use it in GitHub Desktop.
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
Copy link
Author

yarbelk 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