function pram_view ( )

%*****************************************************************************80
%
%% pram_view() plots a solution to the pram tiling problem.
%
%  Discussion:
%
%    There are 64 tiles, selected from the 209 tiles of the Eternity set.
%
%    The pram region is defined by a boundary word.
%
%    Each of the 64 tiles must be assigned a rotation (0-5), reflection (0/1),
%    and (i,j) base point (-22:34, 0:150), in such a way that every elemental
%    triangle of the pram region is covered exactly once, and no elemental
%    triangle of any tile falls outside the region.
%
%    The data for the arrays defining the rotations, reflections, and
%    translations was compiled by hand, tediously.  A few flaws in the
%    designation of base points were discovered, and three incorrect
%    boundary words for tiles were discovered, thanks to this painful
%    investigation.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    30 October 2021
%
%  Author:
%
%    John Burkardt
%
  addpath ( '../eternity' );
  addpath ( '../pram' );

  timestamp ( );

  fprintf ( 1, '\n' );
  fprintf ( 1, 'pram_view():\n' );
  fprintf ( 1, '  MATLAB/Octave version %s\n', version ( ) );
  fprintf ( 1, '  There is a known solution to the pram tiling problem.\n' );
  fprintf ( 1, '  Display the region and the tiles, as positioned by hand.\n' );
%
%  Specify the number of tiles.
%
  tile_num = 64;
%
%  List the rotation of each tile, as a multiple of 60 degrees.
%
  pram_tile_rotation = [ ...
    5,  1,  2,  4,  1,  4,  5,  0,  4,  4, ...
    2,  0,  4,  2,  1,  2,  2,  5,  1,  0, ...
    5,  5,  5,  2,  5,  4,  1,  2,  5,  4, ...
    0,  0,  4,  4,  1,  0,  1,  4,  0,  4, ...
    0,  4,  4,  5,  1,  5,  4,  3,  1,  4, ...
    2,  0,  1,  5,  4,  5,  4,  2,  4,  0, ...
    2,  5,  4,  3 ];
%
%  List whether a tile is not reflected or reflected.
%
  pram_tile_reflection = [ ...
    0,  1,  1,  0,  0,  0,  1,  0,  1,  0, ...
    0,  1,  1,  1,  1,  0,  1,  1,  0,  0, ...
    1,  0,  1,  1,  1,  1,  0,  1,  0,  0, ...
    1,  0,  1,  0,  1,  0,  0,  0,  0,  1, ...
    0,  1,  1,  0,  0,  0,  1,  0,  1,  0, ...
    0,  1,  1,  1,  0,  1,  0,  1,  1,  0, ...
    0,  0,  0,  0 ];
%
%  List the (i,j) coordinates of the base point of the translated tile.
%
  pram_tile_translation = [ ...
    -14,  42; ...
     16,  48; ...
     18,  90; ...
    -16,  84; ...
     22, 102; ...
     -2,  66; ...
     12,  96; ...
      8,   0; ...
    -16,  48; ...
      8,  48; ...
      8,  24; ...
      4,  60; ...
     -2,  66; ...
     12,  12; ...
     24, 144; ...
      6,  54; ...
     20, 120; ...
     -6, 114; ...
     28, 120; ...
    -14,  42; ...
      0, 120; ...
     -4,  48; ...
      8, 108; ...
     16,  48; ...
    -16,  84; ...
      4,  60; ...
     18,  90; ...
     18,  30; ...
     20, 120; ...
    -10,  90; ...
      8,  36; ...
    -16,  60; ...
    -12,  48; ...
      2,  78; ...
     -4,  24; ...
    -10,  66; ...
     -2,  78; ...
      6,  54; ...
      4, 120; ...
      4,  12; ...
     -8,  36; ...
      2, 138; ...
     18,   6; ...
      6, 150; ...
      0,   0; ...
     16, 144; ...
      2, 126; ...
     -2,  66; ...
     10, 138; ...
     -2, 102; ...
     14,  18; ...
      2, 102; ...
     14, 150; ...
     12, 120; ...
      8,  84; ...
     14,  18; ...
      2, 102; ...
     10, 138; ...
     10,  78; ...
     -8,  24; ...
      2, 102; ...
     24, 144; ...
     -8, 108; ...
     10, 114 ];
%
%  Now go through the motions of generating every possible tile configuration.
%  When you have generated the word corresponding to a tile which is part of
%  the solution, add that to the plot.
%
  color = 2;
%
%  Define the region R.
%    W_R: boundary word for R.
%    PIJ_R: (I,J) coordinates of 30-degree node of triangle #1 of R.
%
  [ w_r, pij_r ] = pram_boundary_word ( );
  figure ( );
  region_grid_ij_plot ( w_r, pij_r );
  label = 'pram solution (i,j)';
  title ( label );
%
%  Analyze the region R.
%    TK_R: for each triangle in R, the indices of the 30, 60, 90 degree nodes.
%    TT_R: for each triangle in R, the triangle type, between -6 and -1, or 1 and 6.
%    WIJ_R: (I,J) coordinates of the nodes of R.
%
  [ tk_r, tt_r, wij_r ] = triangle_k ( w_r, pij_r );

  element_num = size ( tt_r, 1 );
%
%  Loop over tiles.
%
  for tile_s = 1 : tile_num
%
%  Get the Eternity ID corresponding to the Pram ID.
%
    tile_e = pram_tile_id ( tile_s );
    fprintf ( 1, 'Processing Pram tile %d, with Eternity id %d\n', tile_s, tile_e );
%
%  Get the boundary word for this tile, using the Eternity ID.
%
    [ w_s, pij_s ] = eternity_tile_word ( tile_e );
%
%  Choose counterclockwise rotation r: 0/1/2/3/4/5
%
    r_s = pram_tile_rotation ( tile_s );
    fprintf ( 1, 'r_s = %d\n', r_s );
%
%  Apply rotation:
%
    [ w_s, pij_s ] = word_rotate_ij ( w_s, pij_s, r_s );
%
%  Choose reflection, 0/1.
%
    reflect_s = pram_tile_reflection ( tile_s );
    fprintf ( 1, 'ref_s = %d\n', reflect_s );
%
%  Apply reflection:
%
    if ( reflect_s == 1 )
      [ w_s, pij_s ] = word_reflect_ij ( w_s, pij_s );
    end
%
%  Get the translation: (i,j)
%
    pij_s = pram_tile_translation ( tile_s, 1:2 );
    fprintf ( 1, 'pij_s = %d, %d\n', pij_s );
%
    color = color + 1;
    tile_overlay_ij_plot ( w_s, pij_s, color );

  end

  axis ( 'off' );

  filename = 'pram_view.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );
%
%  Terminate.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'pram_view():\n' );
  fprintf ( 1, '  Normal end of execution.\n' );
  timestamp ( );

  rmpath ( '../pram' );
  rmpath ( '../eternity' );

  return
end
function timestamp ( )

%*****************************************************************************80
%
%% timestamp() prints the current YMDHMS date as a timestamp.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    14 February 2003
%
%  Author:
%
%    John Burkardt
%
  t = now;
  c = datevec ( t );
  s = datestr ( c, 0 );
  fprintf ( 1, '%s\n', s );

  return
end

