clear;

N = 100000;

X = zeros(2,N);

T{1} = [0;0] ; % Bottom Left Square

T{2} = [1/3;0] ; % Bottom Center Square

T{3} = [2/3;0] ; % Bottom Right Square

T{4} = [0;1/3] ; % Mid Left Square

T{5} = [2/3;1/3] ; % Mid Right Square

T{6} = [0;2/3] ; % Top Left Square

T{7} = [1/3;2/3] ; % Top Center Square

T{8} = [2/3;2/3] ; % Top Right Square

X(:,1) = [0.1; 0.1]; % initial point (Xo=0.1,Yo=0.1, is column 1 of the table)

for i = 1:N-1

Rule = floor(8*rand)+1; %Picks a random number between 1 and 8

X(:,i+1) = 1/3*X(:,i)+T{Rule};

end

figure(1);

set(gcf, 'color', 'white'); % Sets the background Color of the plot to white

% plots all points at the end

% Pick yourt preferred Dot Color from combining (0 to 1 values)

% [ r g b ] = [red green blue];

% [0 0 0] = black,

% [1 1 1] = white,

% [1 0 0 ] = red,

% [0 1 0 ] = green,

% [0 0 1 ] = blue, etc.

% What color is [0.5 0.5 0.5 ] = ?

plot(X(1,:),X(2,:),'.','Color',[0 0 1 ],'MarkerSize',2);

axis off;