function mario_rgb_to_gray ( rule )

  MARIO = [ ...
   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 ( MARIO );

%
%  0: white
%  1: black
%  2: red
%  3: blue
%  4: yellow
%  5: beige
%  6: brown
%
  clf
  hold on

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

      k = MARIO(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
%
%  Rule #1: Gray = AVERAGE ( R, G, B );
%
      if ( rule == 1 )
        g = sum ( color ) / 3.0;
        color = [ g, g, g ];
      elseif ( rule == 2 )
        g = 0.299 * color(1) + 0.587 * color(2) + 0.114 * color(3);
        color = [ g, g, g ];
      end

      a = j - 1;
      b = j;
      c = m - i + 1;
      d = m - i;
      fill ( [ a, b, b, a ], [ c, c, d, d ], color );

    end
  end
  axis equal
  axis off 
  hold off

  if ( rule == 1 )
    print ( '-djpeg', 'mario_rule1.jpg' );
  elseif ( rule == 2 )
    print ( '-djpeg', 'mario_rule2.jpg' );
  end

  return
end
