function mario ( )

%*****************************************************************************80
%
%% mario creates an image of Mario using polygons filled with colors.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    14 October 2019
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'mario:\n' );
  fprintf ( 1, '  MATLAB version\n' );
  fprintf ( 1, '  Draw a picture of Mario, using the fill() command\n' );
  fprintf ( 1, '  to fill polygons with colors.\n' );
%
%  Color indices:
%
%  0: white
%  1: black
%  2: red
%  3: blue
%  4: yellow
%  5: beige
%  6: brown
%
  colors = [ ...
    0, 0, 0, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0; ...
    0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0; ...
    0, 0, 6, 6, 6, 5, 5, 5, 1, 5, 0, 0, 0; ...
    0, 6, 5, 6, 5, 5, 5, 5, 1, 5, 5, 5, 0; ...
    0, 6, 5, 6, 6, 5, 5, 5, 5, 1, 5, 5, 5; ...
    0, 6, 6, 5, 5, 5, 5, 5, 1, 1, 1, 1, 0; ...
    0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0; ...
    0, 0, 2, 2, 3, 2, 2, 2, 2, 0, 0, 0, 0; ...
    0, 2, 2, 2, 3, 2, 2, 3, 2, 2, 2, 0, 0; ...
    2, 2, 2, 2, 3, 3, 3, 3, 2, 2, 2, 2, 0; ...
    5, 5, 2, 3, 4, 3, 3, 4, 3, 2, 5, 5, 0; ...
    5, 5, 5, 3, 3, 3, 3, 3, 3, 5, 5, 5, 0; ...
    5, 5, 3, 3, 3, 3, 3, 3, 3, 3, 5, 5, 0; ...
    0, 0, 3, 3, 3, 0, 0, 3, 3, 3, 0, 0, 0; ...
    0, 6, 6, 6, 0, 0, 0, 0, 6, 6, 6, 0, 0; ...
    6, 6, 6, 6, 0, 0, 0, 0, 6, 6, 6, 6, 0];

  [ m, n ] = size ( colors );
%
%  Fill the I,J box with color K.
%  Actually, "I" becomes M-I+1, because matrix row 1 is at the top,
%  but cell row 1 is at the bottom.
%
%  (m-i,j-1) <------ (m-i,j)
%      |                 ^
%      |                 |
%      |    Color K      |
%      V                 |
%                        |
%  (m-i+1,j-1) ----> (m-i+1,j)
%
  clf ( );
  hold ( 'on' );

  for i = 1 : m
    for j = 1 : n

      k = colors(i,j);

      if ( k == 0 )
        color = [ 1.0, 1.0, 1.0 ];
      elseif ( k == 1 )
        color = [ 0.0, 0.0, 0.0 ];
      elseif ( k == 2 )
        color = [ 1.0, 0.0, 0.0 ];
      elseif ( k == 3 )
        color = [ 0.0, 0.0, 1.0 ];
      elseif ( k == 4 )
        color = [ 1.0, 1.0, 0.0 ];
      elseif ( k == 5 )
        color = [ 1.0, 0.8, 0.6 ];
      elseif ( k == 6 )
        color = [ 0.8, 0.4, 0.0 ];
      end
%
%  Determine "x" and "y" coordinates of the corners of a square,
%  corresponding to "i" and "j".
%  The "y" coordinate has to be reversed.
%
      a = j - 1;
      b = j;
      c = m - i + 1;
      d = m - i;
%
%  Fill the polygon with the given color.
%
      fill ( [ a, b, b, a ], [ c, c, d, d ], color );

    end
  end

  axis ( 'equal' )
  axis ( 'off' )
  hold ( 'off' )
%
%  Save the plot in a file.
%
  filename = 'mario.png';
  print ( '-djpeg', filename );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );
%
%  Terminate.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'mario:\n' );
  fprintf ( 1, '  Normal end of execution.\n' );

  return
end
