MATLAB COMPILER RELEASE NOTES Guida Utente Pagina 61

  • Scaricare
  • Aggiungi ai miei manuali
  • Stampa
Vedere la pagina 60
A Simple Example - The Sierpinski Gasket
3-3
A Simple Example - The Sierpinski Gasket
Consider an M-file function called gasket.m.
function theImage = gasket(numPoints)
%GASKET An image of a Sierpinski Gasket.
% IM = GASKET(NUMPOINTS)
%
% Example:
% x = gasket(50000);
% imagesc(x);colormap([1 1 1;0 0 0]);
% axis equal tight
% Copyright (c) 1984-98 by The MathWorks, Inc
% $Revision: 1.1 $ $Date: 1998/09/11 20:05:06 $
theImage = zeros(1000,1000);
corners = [866 1;1 500;866 1000];
startPoint = [866 1];
theRand = rand(numPoints,1);
theRand = ceil(theRand*3);
for i=1:numPoints
startPoint = floor((corners(theRand(i),:)+startPoint)/2);
theImage(startPoint(1),startPoint(2)) = 1;
end
How the Function Works
This function determines the coordinates of a Sierpinski Gasket using an
IteratedFunctionSystemalgorithm.Thefunction startswitht hree pointsthat
define a triangle, and starting at one of these points, chooses one of the
remaining points atrandom.A dot isplacedatthemidpointofthesetwopoints.
From the new point, a dot is placed at the midpoint between the new point and
a point randomly selected from the original points. This process continues and
eventually leads to an approximation of a curve.
Vedere la pagina 60
1 2 ... 56 57 58 59 60 61 62 63 64 65 66 ... 263 264

Commenti su questo manuale

Nessun commento