Skip to content

Instantly share code, notes, and snippets.

@pollend
Created September 18, 2017 17:14
Show Gist options
  • Save pollend/cc97bfde420323277a2263af810b6206 to your computer and use it in GitHub Desktop.
Save pollend/cc97bfde420323277a2263af810b6206 to your computer and use it in GitHub Desktop.
animated fractal
[X,Y] = meshgrid(-2:.008:2);
Z = ones(size(X));
h = figure;
for frame = -2:.01:2
for x_ = 1: size(X,1)
for y_ = 1: size(X,2)
u = [X(x_,y_),Y(x_,y_)];
for i = 1:100
% julian set
% v = [u(1) * u(1) - u(2) * u(2) + -0.550, u(2) * u(1) + u(2) * u(1)+ -0.550];
% mandelbrot set
% v = [(u(1) * u(1) - u(2) * u(2)) + X(x_,y_), (u(2) * u(1) + u(2) * u(1)) + Y(x_,y_)];
v = [(u(1) * u(1) - u(2) * u(2)) + frame, (u(2) * u(1) + u(2) * u(1)) ];
if((v(1) * v(1) + v(2) * v(2)) > 4)
break
end
u = v;
Z(x_,y_) = i;
end
end
end
fx = X(:);
fy = Y(:);
imagesc(fx,fy,Z)
drawnow
result = getframe(h);
im = frame2im(result);
[imind,cm] = rgb2ind(im,256);
if frame == -2
imwrite(imind,cm,'final.gif','gif', 'Loopcount',inf);
else
imwrite(imind,cm,'final.gif','gif','DelayTime',0.1,'WriteMode','append');
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment