function triangle_ijk_fill ( i, j, k, r, color )

%*****************************************************************************80
%
%% triangle_ijk_fill plots a filled triangle.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    20 August 2020
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer I, J, K, the indices of the cell.
%
%    real R, a size factor for the triangles, between 0 and 1.
%
%    color COLOR, can be any of the 8 abbreviated color terms
%    'r', 'g', 'b', 'c', 'm', 'y', 'w', 'k', or an RGB triple such as 
%    [1.0,0.4,0.0].  The circle is filled with this color.
%
  if ( k == 0 )
    x1 = i - 1 + ( j - 1 ) / 2;
    x2 = i     + ( j - 1 ) / 2;
    x3 = i - 1 +   j       / 2;
    y1 = ( j - 1 ) * sin ( pi / 3.0 );
    y2 = ( j - 1 ) * sin ( pi / 3.0 );
    y3 =   j       * sin ( pi / 3.0 );
  elseif ( k == 1 )
    x1 = i     +   j       / 2;
    x2 = i - 1 +   j       / 2;
    x3 = i     + ( j - 1 ) / 2;
    y1 =   j       * sin ( pi / 3.0 );
    y2 =   j       * sin ( pi / 3.0 );
    y3 = ( j - 1 ) * sin ( pi / 3.0 );
  else
    fprintf ( 1, '\n' );
    fprintf ( 1, 'triangle_ijk_fill - Fatal error!\n' );
    fprintf ( 1, '  Triangle has illegal k index = %d.\n', k );
    error ( 'triangle_ijk_fill - Fatal error!' );
  end

  xm = ( x1 + x2 + x3 ) / 3.0;
  ym = ( y1 + y2 + y3 ) / 3.0;

  x1 = r * x1 + ( 1.0 - r ) * xm;
  x2 = r * x2 + ( 1.0 - r ) * xm;
  x3 = r * x3 + ( 1.0 - r ) * xm;
  y1 = r * y1 + ( 1.0 - r ) * ym;
  y2 = r * y2 + ( 1.0 - r ) * ym;
  y3 = r * y3 + ( 1.0 - r ) * ym;

  fill ( [ x1, x2, x3 ], [ y1, y2, y3 ], color );

  return
end
