% triangle_fill.m
% Make some filled plots involving a triangle.
%
%  Plot 1: 
%  To fill a triangle, you only need each corner once.
%
txlist = [ 0.0, 2.0, 1.0 ];
tylist = [ 0.0, 1.0, 3.0 ];
fill ( txlist, tylist, 'r' );
grid on
title ( 'triangle\_fill1: Triangle fill()', 'FontSize', 24 );
xlabel ( '<-- X -->' );
ylabel ( '<-- Y -->' );
axis equal
print ( '-djpeg', 'triangle_fill1.jpg' );
fprintf ( 'Press RETURN for next plot:\n' );
pause
%
%  Plot 2: 
%  To fill a triangle, plot its outline.
%
txlist = [ 0.0, 2.0, 1.0 ];
tylist = [ 0.0, 1.0, 3.0 ];
fill ( txlist, tylist, 'r' );

hold on
txlist = [ 0.0, 2.0, 1.0, 0.0 ];  % Repeated x coordinate of first point.
tylist = [ 0.0, 1.0, 3.0, 0.0 ];  % Repeated y coordinate of first point.
plot ( txlist, tylist, 'b', 'LineWidth', 10 );
hold off

grid on
title ( 'triangle\_fill2: Triangle fill() + Triangle plot()', 'FontSize', 24 );
xlabel ( '<-- X -->' );
ylabel ( '<-- Y -->' );
axis equal
print ( '-djpeg', 'triangle_fill2.jpg' );
fprintf ( 'Press RETURN for next plot:\n' );
pause
%
%  Plot 3: 
%  Fill triangle and square.
%
txlist = [ 0.0, 2.0, 1.0 ];
tylist = [ 0.0, 1.0, 3.0 ];
fill ( txlist, tylist, 'r' );
sxlist = [ 0.0, 1.0, 1.0, 0.0];
sylist = [ 0.0, 0.0, 1.0, 1.0 ];
orange = [ 1.0, 0.4, 0.0 ];
hold on
fill ( sxlist, sylist, orange );
hold off
grid on
title ( 'triangle\_fill3: Triangle, hold on, square, hold off', 'FontSize', 24 );
xlabel ( '<-- X -->' );
ylabel ( '<-- Y -->' );
axis equal
print ( '-djpeg', 'triangle_fill3.jpg' );
fprintf ( 'Press RETURN for next plot:\n' );
pause
%
%  Plot 4: 
%  Triangle pattern.
%
clf
hold on
for i = 0 : 2
  for j = 0 : i
    fill ( [ 2-i+2*j, 4-i+2*j, 3-i+2*j ], [ 2-i, 2-i, 3-i ], 'c' )
  end
end
hold off
grid on
title ( 'triangle\_fill4: Triangle Tiles, Double FOR Loop', 'FontSize', 24 );
xlabel ( '<-- X -->' );
ylabel ( '<-- Y -->' );
axis equal
print ( '-djpeg', 'triangle_fill4.jpg' );
fprintf ( 'Press RETURN to finish:\n' );
pause
