function myifsgasket(max_iterations) parameters =[ 1/2 1/2 0 0 0; 1/2 1/2 0 1/4 3^(1/2)/4; 1/2 1/2 0 1/2 0]; [n,m] = size(parameters); xscale = parameters(:,1); yscale = parameters(:,2); theta = parameters(:,3); shift = [ parameters(:,4)'; parameters(:,5)' ]; Map = zeros(2,2,n); for i=1:n rotation = [ cosd(theta(i)) -sind(theta(i)) ; sind(theta(i)) cosd(theta(i)) ]; scale = [ xscale(i) 0 ; 0 yscale(i) ]; Map(:,:,i) = rotation*scale; end x = zeros(2,max_iterations); y = [0;0]; for i = 1:100 pick = randi([1 n]); y = Map(:,:,pick)*y + shift(:,pick); end x(:,1) = y; for i = 2:max_iterations pick = randi([1 n]); x(:,i) = Map(:,:,pick)*x(:,i-1) + shift(:,pick); end plot(x(1,:),x(2,:),'b.','MarkerSize',0.1) axis equal %axis off end