4 ms·
In his honor, here is Matlab code to generate a Mandlebrot set (from an old homework assignment): function inValues= mndl(limits) %no inputs needed, used by th
by secret 16y ago
In his honor, here is Matlab code to generate a Mandlebrot set (from an old homework assignment):
function inValues= mndl(limits) %no inputs needed, used by the script to zoom in
%amount of detail to calculate; larger number = better resolution, slower calculation
stepsR=300;
stepsI=300;
%maximum iterations used in calculations
maxIter=50;
if exist('limits')~=1; %intial range of real and imaginary numbers to compute
lowerR=-2;
lowerI=-1.25;
higherR=1;
higherI=1.25;
else numel(limits)==4; %range to compute after zooming in, determined by axis
lowerR=limits(1);
lowerI=limits(3);
higherR=limits(2);
higherI=limits(4);
end
%Constants:
slR=(higherR-lowerR)/(stepsR-1);
slI=(higherI-lowerI)/(stepsI-1);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Create the Mandelbrot image.
[x,y]=meshgrid([0:stepsR-1]slR+lowerR,[0:stepsI-1]slI+lowerI);
inValues=ones(size(x));
z=zeros(size(x));
c=(x+1iy);
h_z=1:(stepsRstepsI);
for counter=1:maxIter
z(h_z)=z(h_z).^2+c(h_z);
h_z= h_z(abs(z(h_z))<2);
inValues(h_z)=inValues(h_z)+1;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%format presentation of Mandelbrot image
colormap jet;
pcolor(x,y,log(double(inValues)));
title('Mandelbrot Image: Zoom In and Sharpen for Details');
shading interp;
axis off;
zoom %turn on zoom feature initially
clear inValues
%Buttons:
%recalculate image to enhance after zooming in (just calls the function
%again with new input argument based on current axis)
h1= uicontrol('Parent',gcf,'Units','points', ...
'Callback',['mndl(axis);zoom;'], ...
'Position',[105 5 105 20],'Style','pushbutton','String','Sharpen (after zooming in)');
%turn the zoom button on or off
h2= uicontrol('Parent',gcf,'Units','points', ...
'Callback',['zoom'], ...
'Position',[215 5 55 20],'Style','pushbutton','String','Zoom On/Off');
%reset the image
h3= uicontrol('Parent',gcf,'Units','points', ...
'Callback',['mndl();zoom;'], ...
'Position',[275 5 40 20],'Style','pushbutton','String','Reset');
- secret 16y agoSorry about the weird formatting, it looks fine when I paste in the comment box. You'll need to add line breaks after the comments to get it working.
- seancron 16y agoYou might want to put that code in a site such as http://pastebin.com/ http://pastebin.com/ and link to it instead.
- sesqu 16y agoI think I copied this from HN once. Paste to terminal: dc -e '[lolssdsl0lqx]sx[1+lddd*lld*-ls+dsdrll2**lo+dsld*rd*+4<kd15>q]sq[q]9ksk[d77/3*2-ss47lxx-P1+d78>0]s00[d23/.5-3*so0l0xr10P1+d24>u]dsux'
- GFischer 16y agoThere are some amazing images of fractals on the web. One site that was pointed out here in particular was the Mandelbub, which looks amazing: http://www.skytopia.com/project/fractal/mandelbulb.html http://www.skytopia.com/project/fractal/mandelbulb.html