## 2D Arrays of ASCII Images

posted by: Mr. Bergquist 12 January 2014 No Comment

ASCII art involves making images out of characters (char’s). It turns out that this is not very far from how images really are represented — they’re really just two dimensional arrays of colors. This short assignment will get you to explore how image manipulation programs work. Thanks to Baker Franke for inspiration and Ms. Martin for creating this one.

Just in case, our: 2D Arrays Lecture & its Handout: 2D Arrays

For this assignment, images are represented as a single line of integers. The first two integers give the height and width of the image. The rest are ASCII values specifying which characters to display.  Recall from our earlier Strings Presentation that every common text character maps to a decimal number 0 – 255; slide 18 is very helpful.

• 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-    \ `.  |    |```
• Then 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          `.
( ( ,'"""""-.
,.'-.   \
,---.```

For extra fun, try out:

• Rotating the image 90 degrees
• Enlarge the image
• Shrinking the image
• Inverting the image
• Reflecting it horizontally or vertically
• Making your own ASCII image
• What else can you do with the image, think of what Image processing programs can do.
(8 votes, average: 3.63 out of 5)