function fractal (level, Pt1, Pt2, Pt3)
%defines phi value to be used by different fuctions (the run_fractal func)
global phi

if ( level == 1 )
  %draws a line from Pt1(point 1) to Pt2(point 2)
  line([Pt1(1) Pt2(1)],[Pt1(2) Pt2(2)]);
  %draws a line from Pt2 to Pt3
  line([Pt2(1) Pt3(1)],[Pt2(2) Pt3(2)]);
  hold on
else
    A = [cos(phi) + sin(phi);
        -sin(phi) cos(phi)];
    
    Pt12 = Pt1 + A*(Pt2-Pt1)/sqrt(2); 
    fractal(level-1, Pt1, Pt12, Pt2);

    Pt23 = Pt3 - A*(Pt3-Pt2)/sqrt(2);
    fractal(level-1, Pt2, Pt23, Pt3);
end