#! /usr/bin/env python # def pentomino_display ( p, label ): #*****************************************************************************80 # ## PENTOMINO_DISPLAY displays a particular pentomino in a 5x5 grid. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 18 April 2018 # # Author: # # John Burkardt # # Parameters: # # Input, integer P(P_M,P_N), a matrix of 0's and 1's. # 1 <= P_M, P_N <= 5. There should be exactly 5 values of one. # # Input, string LABEL, a title for the plot. # import matplotlib.pyplot as plt import numpy as np from cell_ij_fill import cell_ij_fill # # The background grid. # grid_m = 5 grid_n = 5 grid = np.zeros ( [ grid_m, grid_n ] ) # # Place the pentomino on the grid, so that it is "snug" in the upper left corner. # dims = p.shape p_m = dims[0] p_n = dims[1] grid[0:p_m,0:p_n] = p[0:p_m,0:p_n] # # Display each square of the grid. # plt.axis ( 'equal' ) plt.axis ( 'off' ) for i in range ( 0, grid_m ): for j in range ( 0, grid_n ): k = grid[i,j] if ( k == 0 ): color = 'white' elif ( k == 1 ): color = 'black' cell_ij_fill ( grid_m, i, j, color ) filename = label + '.png' plt.savefig ( filename ) plt.show ( ) plt.clf ( ) print ( ' PENTOMINO_DISPLAY created "%s"' % ( filename ) ) return def pentomino_display_test ( ): #*****************************************************************************80 # ## PENTOMINO_DISPLAY_TEST tests PENTOMINO_DISPLAY. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 18 April 2018 # # Author: # # John Burkardt # import numpy as np from pentomino_matrix import pentomino_matrix print ( '' ) print ( 'PENTOMINO_DISPLAY_TEST' ) print ( ' PENTOMINO_DISPLAY displays a picture of a pentomino.' ) pentominos = np.array ( \ [ 'F', 'I', 'L', 'N', 'P', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' ] ) for i in range ( 0, 12 ): name = pentominos[i] p = pentomino_matrix ( name ) pentomino_display ( p, name ) return if ( __name__ == '__main__' ): from timestamp import timestamp timestamp ( ) pentomino_display_test ( ) timestamp ( )