No BSD License  

Highlights from
Fratal

image thumbnail
from Fratal by Paul French
Generates the Sierpinski triangle using very simple rules using dice

Fractal.m
% gtenerates a fractal 
% pjfrench@imperial.ac.uk
clear all
close all
rand('state',sum(100*clock))

% three starting points:
P1 = [50,100];
P2 = [0, 0];
P3 = [100,0];
Steps = input('How many steps: ');  % no. of steps
count = 0;                          % internal count
S = floor(rand(1,2)*100);           % starting point


%initial plot before iteration
figure(1)
axis off
hold on
plot(P1(1),P1(2),'r.')
plot(P2(1),P2(2),'r.')
plot(P3(1),P3(2),'r.')
plot(S(1),S(2),'k.')


while(count <= Steps)
    Dice = 1 + floor(rand(1)*6);
    if ( (Dice == 1) || (Dice == 2) )
        x = S(1) + (P1(1)-S(1))*0.5;
        y = S(2) + (P1(2)-S(2))*0.5;
    elseif ( (Dice == 3) || (Dice == 4) )
        x = S(1) + (P2(1)-S(1))*0.5;
        y = S(2) + (P2(2)-S(2))*0.5;
    else
        x = S(1) + (P3(1)-S(1))*0.5;
        y = S(2) + (P3(2)-S(2))*0.5;
    end
    plot(x,y,'k-')
    S(1) = x;
    S(2) = y;
    count = count + 1;   
end

Contact us at files@mathworks.com