Images from ASCII Arrays

posted by: Mr. Bergquist 12 February 2012 No Comment

You have probably seen art where a larger image made up of smaller images, squares, or even individual characters. This assignment involves the latter, making images out of ASCII characters. It turns out that this is not very far from how images really are represented — they’re really just two dimensional arrays of colors, but let’s start simple with characters. This short assignment will get you to explore how image manipulation programs work. Thanks to Baker Franke (& Ms. Martin) for inspiration.

For this assignment, images are represented as a single line of integers in a file. The first two integers give the height and width of the image. The rest are ASCII values specifying which characters to display.

Your program will:

  • Read in an image file. Use homer.txt and mystery.txt for your testing.
  • Create a character array that represents the image.
  • Print out the image (display method). With the homer.txt file, your output should be:
                   ,---.
                ,.'-.   \
               ( ( ,'"""""-.
               `,X          `.
               /` `           `._
              (            ,   ,_\
              |          ,---.,'o `.
              |         / o   \     )
               \ ,.    (      .____,
                \| \    \____,'     \
              '`'\  \        _,____,'
              \  ,--      ,-'     \
                ( C     ,'         \
                 `--'  .'           |
                   |   |         .O |
                 __|    \        ,-'_
                / `L     `._  _,'  ' `.
               /    `--.._  `',.   _\  `
               `-.       /\  | `. ( ,\  \
              _/  `-._  /  \ |--'  (     \
             '  `-.   `'    \/\`.   `.    )
                   \  -hrr-    \ `.  |    |
    
  • Print out the image flipped horizontally (displayFlippedHoriz). With the homer.txt file, your output should be:
                        .---,
                       \   .-'.,
                    .-"""""', ( (
                  .`          X,`
               _.`           ` `/
              \_,   ,            (
            .` o',.---,          |
           )     \   o /         |
            ,____.      (    ., \
           \     ',____\    \ |\
           ',____,_        \  \'`'
             \     '-,      --,  \
            \         ',     C (
           |           '.  '--`
           | O.         |   |
           _'-,        \    |__
         .` '  ',_  _.`     L` /
        `  \_   .,'`  _..--`    /
       \  \, ( .` |  \/       .-`
      \     (  '--| \  /  _.-`  /_
     )    .`   .`\/\    '`   .-`  '
     |    |  .` \    -rrh-  \
    

    Note that the characters themselves don’t flip!

  • Print out the image flipped vertically (displayFlippedVert). With the homer.txt file, your output should be:
                   \  -hrr-    \ `.  |    |
             '  `-.   `'    \/\`.   `.    )
              _/  `-._  /  \ |--'  (     \
               `-.       /\  | `. ( ,\  \
               /    `--.._  `',.   _\  `
                / `L     `._  _,'  ' `.
                 __|    \        ,-'_
                   |   |         .O |
                 `--'  .'           |
                ( C     ,'         \
              \  ,--      ,-'     \
              '`'\  \        _,____,'
                \| \    \____,'     \
               \ ,.    (      .____,
              |         / o   \     )
              |          ,---.,'o `.
              (            ,   ,_\
               /` `           `._
               `,X          `.
               ( ( ,'"""""-.
                ,.'-.   \
                   ,---.
    

Extensions: rotate 90, enlarge, shrink, invert…

1 Star2 Stars3 Stars4 Stars5 Stars (2 votes, average: 5.00 out of 5)
Loading ... Loading ...

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>