function ijk_fill ( ijk, r, color, label )

%*****************************************************************************80
%
%% ijk_fill() plots a filled ijk triangle.
%
%  Discussion:
%
%    The (i,j) coordinates refer to a grid whose basic cell
%    is the unit square outlined by points (A,B,C,D):
%      A = (0,0) --> B = (1,0) --> C = (1,1) --> D = (0,1).
%
%      D-----C
%      |     |
%      |     |
%      |  E  |
%      |     |
%      |     |
%      A-----B
%
%    Each cell is divided into triangles with index k = 0, 1, 2, 3:
%
%      D-----C
%      |\ 2 /|
%      | \ / |
%      |3 E 1|
%      | / \ |
%      |/ 0 \|
%      A-----B
%
%    Triangles are identified by a related (i,j,k) coordinate based 
%    on the (i,j) coordinates of its vertices:
%      k = 0: A, B, E.
%      k = 1: B, C, E.
%      k = 2: C, D, E
%      k = 3: D, A, E
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    08 December 2021
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer IJK[3], 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.
%
%    string LABEL: an optional label.
%
  [ x, y ] = ijk_to_xy ( ijk );

  xm = sum ( x ) / 3.0;
  ym = sum ( y ) / 3.0;

  x = r * x + ( 1.0 - r ) * xm;
  y = r * y + ( 1.0 - r ) * ym;

  fill ( x, y, color );

  if ( 0 < length ( label ) )
    text ( xm, ym, label, 'HorizontalAlignment', 'center' );
  end

  return
end

