function q = variomino_transform ( p, rotate, reflect )

%*****************************************************************************80
%
%% variomino_transform() transforms a variomino.
%
%  Discussion:
%
%    A polyomino is a shape formed by connecting unit squares edgewise
%
%    A variomino is a polyomino in which each square has been assigned
%    a value between 1 and v.
%
%    A variomino can be represented by an MxN matrix, whose entries are
%    between 1 and v for squares that are part of the variomino, 
%    and 0 otherwise.
%
%    A variomino can be rotated or reflected.
%
%    This program is given a variomino and returns the resulting variomino
%    after the specified reflection and rotation.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    17 April 2023
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer p(mp,np): the matrix representing the variomino.
%
%    integer rotate: is 0, 1, 2, or 3, the number of 90 degree
%    counterclockwise rotations to be applied.
%
%    integer reflect: is 0 or 1.  If it is 1, then each row of the
%    pariomino matrix is to be reflected before any rotations are performed.
%
%  Output:
%
%    integer q(mq,nq): the matrix representing the transformed variomino.
%
  reflect = mod ( reflect, 2 );

  if ( reflect == 1 )
    q = fliplr ( p );
  else
    q = p;
  end

  rotate = mod ( rotate, 4 );

  for k = 1 : rotate
    q = flipud ( q' ); 
  end

  return
end
