function grid_plot ( imin, imax, jmin, jmax, r, color_back, color_tri, number )

%*****************************************************************************80
%
%% grid_plot() displays a parallelogram grid.
%
%  Discussion:
%
%    The user should call "clf()" before this function.
%
%    The user should call "hold('off')" to close this plot.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    16 November 2020
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer IMIN, IMAX, JMIN, JMAX: the range of the parallelogram.
%
%    real R: controls the size of the component triangles.
%    0 <= R<= 1.  Use R=0.95 for triangles that don't completely fill
%    the region.
%
%    color COLOR_BACK, COLOR_TRI: colors for the background and the triangles.
%
%    logical NUMBER: true if the triangle grid indices should be plotted.
%

%
%  Ensure the origin is included.
%
  imin2 = min ( imin, 0 );
  imax2 = max ( imax, 0 );
  jmin2 = min ( jmin, 0 );
  jmax2 = max ( jmax, 0 );
%
%  Determine (x,y) coordinates.
%
  x1 = imin2 - 1 + ( jmin2 - 1 ) / 2;
  y1 =             ( jmin2 - 1 ) * sin ( pi / 3.0 );

  x2 = imax2     + ( jmin2 - 1 ) / 2;
  y2 =             ( jmin2 - 1 ) * sin ( pi / 3.0 );

  x3 = imax2     +   jmax2       / 2;
  y3 =               jmax2       * sin ( pi / 3.0 );

  x4 = imin2 - 1 +   jmax2       / 2;
  y4 =               jmax2       * sin ( pi / 3.0 );

  hold ( 'on' );

  fill ( [ x1, x2, x3, x4 ], [ y1, y2, y3, y4 ], color_back );

  label = '';

  for i = imin2 : imax2
    for j = jmin2 : jmax2
      for k = 0 : 1
        ijk = [ i, j, k ];
        ijk_fill ( ijk, r, color_tri, label );
      end
    end
  end

  if ( number )
    for i = imin : imax
      for j = jmin : jmax
        for k = 0 : 1
          grid_index = 1 + 2 * ( i - 1 + imax * ( j - 1 ) ) + k;
          label = sprintf ( '%d', grid_index );
          ijk = [ i, j, k ];
          ijk_fill ( ijk, r, color_tri, label );
        end
      end
    end
  end
%
%  Mark the origin.
%
  plot ( 0.0, 0.0, 'k.', 'markersize', 35 );

% hold ( 'off' );

  axis ( 'equal' );
  axis ( 'off' );

  return
end

