function p2 = ij_rotate ( p, r )

%*****************************************************************************80
%
%% ij_rotate() rotates (i,j) coordinates through a multiple of 60 degrees.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    11 November 2020
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer P(2): the IJ parallelogram coordinates of a point.
%
%    integer R: the number of 60 degree turns clockwise (R positive) or
%    counterclockwise (R negative)
%
%  Output:
%
%    integer P2(2): the IJ parallelogram coordinates of the rotated point.
%
  p2 = [ p(1); p(2) ];
%
%  Clockwise
%
  if ( 0 < r )

    A = [ 1, 1; ...
         -1, 0 ];

    for k = 1 : r
      p2 = A * p2;
    end
%
%  Counterclockwise
%
  elseif ( r < 0 )

    A = [ 0, -1; ...
          1,  1 ];

    for k = 1 : - r
      p2 = A * p2;
    end

  end

  p2 = p2';

  return
end

