Skip to content

Instantly share code, notes, and snippets.

@pollend
Created September 20, 2017 02:34
Show Gist options
  • Save pollend/717bdda106171c793d9534e08a52b90f to your computer and use it in GitHub Desktop.
Save pollend/717bdda106171c793d9534e08a52b90f to your computer and use it in GitHub Desktop.
zooming into a spiral fractal
h = figure;
set(h, 'Position', [0 0 700 700])
left = linspace(-.75, -.7367,100)
right = linspace(-.72, -.7364,100)
top = linspace(-.7, -.6928,100)
bottom = linspace(-.684, -.6926,100)
for frame = 1:1:100
[X,Y] = meshgrid(linspace(left(frame),right(frame),800),linspace(top(frame),bottom(frame),800));
Z = ones(size(X));
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) + frame, u(2) * u(1) + u(2) * u(1)+ frame];
% 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)) + .3, (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 == 1
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