%BARNSLEY Barnsley's game to compute Sierpinski gasket. rand('state',1) % Set random number state. V = [0, 1, 0.5; 0, 0, sqrt(3)/2]; % Columns give triangle vertices. point = V(:,1); % Start at a vertex. n = input('Enter number of points (try 1000) '); for k = 1:n node = ceil(3*rand); % node is 1, 2, or 3 with equal prob. point = (V(:,node) + point)/2; plot(point(1),point(2),'.','MarkerSize',15) hold on end axis('equal','off') hold off