This assignment should be written in the python programming language. You should only use python features that we have discussed up to this point. If you have questions about whether or not a particular feature can/should be used, ask the instructors! You may use any python version 3.0 or newer.
All of your programming should be well-formatted and easy for the graders to read and comprehend. Each program file should have a header comment at the top that has the following format:
#
# Author: Student Name
# Description:
# A short description of what this program does!
#
If any part of your scripts are particularly complex, you should put documentation comments above those lines of code.
You are to write a program which “flips” the “pixels” of ascii-art images.
ascii-art is an image that is created by assembling rows and columns of characters to resemble an image.
Below are two examples.
The first is an ascii “picture” of a person.
This is saved in a file named person.txt
:
#######
# 0 0 #
# v # %
# O # #
####### #
# #
########
# # #
# # #
# # #
% #####
## ##
## ##
## ##
000 000
And this image is named linux.txt
, and it depicts the penguin logo for linux:
.88888888:.
88888888.88888.
.8888888888888888.
888888888888888888
88' _`88'_ `88888
88 88 88 88 88888
88_88_::_88_:88888
88:::,::,:::::8888
88`:::::::::'`8888
.88 `::::' 8:88.
8888 `8:888.
.8888' `888888.
.8888:.. .::. ...:'8888888:.
.8888.' :' `'::`88:88888
.8888 ' `.888:8888.
888:8 . 888:88888
.888:88 .: 888:88888:
8888888. :: 88:888888
`.::.888. :: .88888888
.::::::.888. :: :::`8888'.:.
::::::::::.888 ' .::::::::::::
::::::::::::.8 ' .:8::::::::::::.
.::::::::::::::. .:888:::::::::::::
:::::::::::::::88:.__..:88888:::::::::::'
`'.:::::::::::88888888888.88:::::::::'
`':::_:' -- '' -'-' `':_::::'`
Notice that each of these images has the exact same number of characters on each row. This is important, because rows in an image must be all of the same length for it to appear “square.” In some cases, this means padding the ends of the lines with space characters. Your program should work on any ascii image file (with any width and height), so don’t just test with these two. We will use these two as a running example for this assignment spec.
You will write a program that flips the characters in these images in various ways.
You program will take three inputs.
The first shall be the name of the file containing the “image” to flip.
The second will be the name of a (new) file to save the flipped image into.
The third will be either “lr” or “ud” (indicating whether to flip the image “left-right” or “up-down”)
You should use the input()
function to grab these values.
An example of reading these values in looks like the following:
Select an image file: res/person.txt
Select an output file: flippedperson.txt
Select a direction (lr, ud): lr
...
Your program must ensure that the third input is lr
or ud
.
If not, it should print a warning message, and then ask for the input again.
It should do this until a correct input is provided.
Flipping person.txt
and linux.txt
in lr mode would result in the output files having these contents (respectively):
#######
# 0 0 #
% # v #
# # O #
# #######
# #
########
# # #
# # #
# # #
##### %
## ##
## ##
## ##
000 000
.:88888888.
.88888.88888888
.8888888888888888.
888888888888888888
88888` _'88`_ '88
88888 88 88 88 88
88888:_88_::_88_88
8888:::::,::,:::88
8888`':::::::::`88
.88:8 '::::` 88.
.888:8` 8888
.888888` '8888.
.:8888888':... .::. ..:8888.
88888:88`::'` ': '.8888.
.8888:888.` ' 8888.
88888:888 . 8:888
:88888:888 :. 88:888.
888888:88 :: .8888888
88888888. :: .888.::.`
.:.'8888`::: :: .888.::::::.
::::::::::::. ' 888.::::::::::
.::::::::::::8:. ' 8.::::::::::::
:::::::::::::888:. .::::::::::::::.
':::::::::::88888:..__.:88:::::::::::::::
':::::::::88.88888888888:::::::::::.'`
`'::::_:'` '-'- '' -- ':_:::'`
Flipping them both in ud mode would result in these contents:
000 000
## ##
## ##
## ##
% #####
# # #
# # #
# # #
########
# #
####### #
# O # #
# v # %
# 0 0 #
#######
`':::_:' -- '' -'-' `':_::::'`
`'.:::::::::::88888888888.88:::::::::'
:::::::::::::::88:.__..:88888:::::::::::'
.::::::::::::::. .:888:::::::::::::
::::::::::::.8 ' .:8::::::::::::.
::::::::::.888 ' .::::::::::::
.::::::.888. :: :::`8888'.:.
`.::.888. :: .88888888
8888888. :: 88:888888
.888:88 .: 888:88888:
888:8 . 888:88888
.8888 ' `.888:8888.
.8888.' :' `'::`88:88888
.8888:.. .::. ...:'8888888:.
.8888' `888888.
8888 `8:888.
.88 `::::' 8:88.
88`:::::::::'`8888
88:::,::,:::::8888
88_88_::_88_:88888
88 88 88 88 88888
88' _`88'_ `88888
888888888888888888
.8888888888888888.
88888888.88888.
.88888888:.
Note that flipping an image in the same direction twice in a row should result in the exact same image as what was started with. I suggest you use this technique to ensure that you are flipping correctly.
When implementing this, you may only use the following built-in list and string functions:
len()
list()
append()
No others should be used!
You man not, use reverse
, or any others.
You must use 2D lists to represent the rows and columns of the text images!
Several example inputs/outputs will be provided in the diff-tester.
It is due on 7/28/2017 at 7:00pm.
You should put all of your code in to a python file named flipper.py
.
Submit flipper.py
to the associated D2L dropbox.
Following these turn-in and naming instructions closely is very important, because our grading scripts will depend on some of the details.
You may lose points if these instructions are not followed precisely!