Skip to content

Instantly share code, notes, and snippets.

@10long
Created October 27, 2017 01:25
Show Gist options
  • Save 10long/4c76d03397ea77592c0c8534cb217467 to your computer and use it in GitHub Desktop.
Save 10long/4c76d03397ea77592c0c8534cb217467 to your computer and use it in GitHub Desktop.
mandebrot sets git animation
def mandelbrot?(z,c,nn)
for n in 1 .. nn
z = z ** 2 + c
if z.real.infinite? || z.real.infinite? || z.imag.infinite? || z.imag.nan?
return [false, n]
end
end
[true, n]
end
require "rmagick"
def make_gif
il = Magick::ImageList.new
il.new_image(400,400)
cs = -2.step(2,0.009).to_a
cs = cs.product(cs)
for y,x in cs
m = mandelbrot?(Complex(0,0),Complex(x,y),100)
c = 65535/100*m[1]
il.pixel_color(200+100*x,200+100*y,Magick::Pixel.new(0,c,0))
end
il.write("mandelbrot.gif")
end
def make_animation_gif(my,mx,d,fs)
il = Magick::ImageList.new
scale = 1
cs = -2.step(2,d).to_a
cs = cs.product(cs)
palette = []
1.upto(100) do |n|
c = 65535 / 100 * n
palette[n] = Magick::Pixel.new(0, c, 0)
end
for n in 1 .. fs
il.new_image(400,400) {
self.background_color = "black"
}
for y,x in cs
cy = scale * y + my
cx = scale * x + mx
m = mandelbrot?(Complex(0,0),Complex(cx,cy),100)
il.pixel_color(200+100*x,200+100*y,palette[m[1]])
end
scale = scale * 0.9
p n
il.write("mandelbrot_abs_zoom.gif")
end
end
#make_gif
make_animation_gif(-0.09445, -1.264405, 0.009, 150)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment