function chaos(steps)

% CHAOS(STEPS) simulates the game of chaos by Michael F. Barnsley
% resulting in the Sierpinski triangle. STEPS is the number 
% of iterations and therefore the number of points 
% in the resulting image.
% The three reference points are named a, b, c.

% CHAOS uses steps = 1000.

% This file was generated by students as a partial fulfillment 
% for the requirements of the course "Fractals", Winter term
% 2004/2005, Stuttgart University.	
	
% Author : Raphael Loechner
% Date   : Nov 2004
% Version: 1.0

if nargin ~= 1      % default setting
	steps = 1000;
end

clf;                % clear screen
axis square;              
hold on;            % overlay plot (all points on the same image)

a = [0;0];            % reference points
b = [50;100];
c = [100;0];


spielpkt = rand(2,1)*100;      % choose starting point randomly

for n = 1:steps                
    wuerfel = rand(1);         % roll a dice (a, b or c)
    if wuerfel < 1/3 
        mal = (a-spielpkt)/2 + spielpkt;     % next point?
    elseif wuerfel > 2/3
        mal = (c-spielpkt)/2 + spielpkt;
    else mal = (b-spielpkt)/2 + spielpkt;
    end
    spielpkt = mal;            % new point
    x = mal(1);               
    y = mal(2);                
    plot(x,y,'o');             % plot the current point
end                            % next iteration
