#*****************************************************************************80 # ## mario_fill creates an image of Mario using colored squares. # # Licensing: # # This code is distributed under the MIT license. # # Modified: # # 01 September 2020 # # Author: # # John Burkardt # cat ( date ( ), "\n" ) cat ( "\n" ) cat ( "mario_fill\n" ) cat ( " ", version$version.string, "\n" ) cat ( " Draw a picture of Mario, using the polygon() command" ) cat ( " to create a grid of colored squares." ) # # Color indices: # # 0: white # 1: black # 2: red # 3: blue # 4: yellow # 5: beige # 6: brown # colors <- c ( "white", "black", "red", "blue", "yellow", "burlywood1", "brown" ) color_index <- matrix ( c ( 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 ), 13 ) m = 13; n = 16; filename = "mario_fill.png" png ( filename ) # # Apparently, I have to call "plot" before I can call polygon. # par ( pty = 's' ) plot ( c ( 0, m, m, 0 ), c ( 0, 0, n, n ), col = 'white', xlab = '', xaxt = 'n', ylab = '', yaxt = 'n', bty = 'n', main = "Mario" ) for ( j in 1 : n ) { a = n - j + 1 b = n - j for ( i in 1 : m ) { c = i - 1 d = i # c = m - i + 1 # d = m - i polygon ( c ( c, d, d, c ), c ( a, a, b, b ), density = NULL, border = "black", col = colors[color_index[i,j]+1] ) } } cat ( ' Graphics saved as "', filename, '"\n' ) # # Terminate. # cat ( "\n" ) cat ( "mario_fill:\n" ) cat ( " Normal end of execution.\n" ) quit ( )