Question
You will write a program named flipper.py that flips the pixels of ascii-art images. Ascii-art is an image that is created by assembling rows and
You will write a program named flipper.pythat flips the pixels of ascii-art images. Ascii-art is an image that is created by assembling rows and columns or 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 |
The second ascii image file is vader.txt, and it shows Darth Vader:
.-. |_:_| /(_Y_)\ . ( \/M\/ ) '. _.'-/'-'\-'._ ': _/.--'[[[[]'--.\_ ': /_' : |::"| : '.\ ': // ./ |oUU| \.' :\ ': _:'..' \_|___|_/ : :| ':. .' |_[___]_| :.':\ [::\ | : | | : ; : \ '-' \/'.| |.' \ .;.' | |\_ \ '-' : | | \ \ .: : | | | \ | '. : \ | / \ :. .; | / | | :__/ : \\ | | | \: | \ | || / \ : : |: / |__| /| | : : :_/_| /'._\ '--|_\ /___.-/_|-' \ \ |
Notice that each of these images has the same exact number of characters on each row. This is important because rows in an image must all be of the same length for it to appear square. For the case of these files, this means padding the ends of the lines with space characters. Your program should work on anyascii image file, with any width and height), so do not just test with these two. These are just two as a running example for this assignment spec.
You will write a program that flips the characters in these images in various ways. Your program will take three inputs. The first should be the name of the file containing the image to flip. The second will be the name of the newfile to save the flipped image. The third will be either lr (left-right)or ud (up-down). You would use the input()function to get these values.
Select an image file: person.txt Select an output file: person_lr.txt Select a direction (lr, ud): lr |
Your program must ensure that the third input is eitherlror ud. If it does not match either input, then print a warning message and then ask for the input again. It SHould do this until a correct input is provided.
Flippingperson.txt and vader.txt in lr mode should result in the outfiles having these contents respectively:
####### # 0 0 # % # v # # # O # # ####### # # ######## # # # # # # # # # ##### % ## ## ## ## ## ## 000 000 |
.-. |_:_| \)_Y_(/ ) /\M/\ ( . _.'-\'-'/-'._ .' _\.--'][[[['--./_ :' \.' : |"::| : '_/ :' \: '.\ |UUo| /. // :' |: : /_|___|_\ '..':_ :' \:'.: |_]___[_| '. .:' \ : ; : | | : | \::[ | '.;. \ '.| |.'/\ '-' | : '-' \ _\| | | : :. \ \ | | \ : .' | \ | | ;. .: \ / \\ : /__: | | / || | \ | :\ | | | |/ |__| / :| : : \ / \_|--' \_.'/ |_/_: : : | \ \ '-|_/-.___/ |
Flipping both files in udmode should result in the following contents:
000 000 ## ## ## ## ## ## % ##### # # # # # # # # # ######## # # ####### # # O # # # v # % # 0 0 # ####### |
/___.-/_|-' \ \ | : : :_/_| /'._\ '--|_\ / \ : : |: / |__| /| | | | \: | \ | || / | | :__/ : \\ / \ :. .; | | \ | '. : \ | | \ \ .: : | | |\_ \ '-' : | '-' \/'.| |.' \ .;.' | [::\ | : | | : ; : \ ':. .' |_[___]_| :.':\ ': _:'..' \_|___|_/ : :| ': // ./ |oUU| \.' :\ ': /_' : |::"| : '.\ ': _/.--'[[[[]'--.\_ '. _.'-/'-'\-'._ . ( \/M\/ ) /(_Y_)\ |_:_| .-. |
Note that flipping an image in the same direction twice in a row should result in the same exact image as the original. Use this technique to ensure that your are flipping correctly
When writing your program, you may only use the following built-in list and string methods:
len()
list()
append()
replace()
strip()
No other built-in methods can be used! You can not use reverse(), or any others! You must use 2D lists to represent the rows and columns of the text images!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started