Skip to content

Instantly share code, notes, and snippets.

@jcchurch
Created January 25, 2013 17:59
Show Gist options
  • Save jcchurch/4636499 to your computer and use it in GitHub Desktop.
Save jcchurch/4636499 to your computer and use it in GitHub Desktop.
function mandelbrot()
% Generates a mandelbrot set image
delta = 0.01;
xmin = -2.5;
xmax = 1;
ymin = -1;
ymax = 1;
colors = char('r.', 'g.', 'b.', 'c.', 'm.');
num_colors = size(colors, 1);
xrange = xmin:delta:xmax;
yrange = ymin:delta:ymax;
hold on;
for thisx = xrange
for thisy = yrange
x = 0;
y = 0;
iteration = 0;
max_iteration = 1000;
while x*x + y*y < 2*2 & iteration < max_iteration
xtemp = x*x - y*y + thisx;
y = 2*x*y + thisy;
x = xtemp;
iteration = iteration + 1;
end
color = colors(mod(iteration-1,num_colors)+1,:);
plot(thisx, thisy, color);
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment