Comp 115 Programming Assignment 05:
Asciimation

Due 11:59pm Monday, April 27 2020

You are required to work on this lab in teams of two. You must complete this lab with your teammate only, although you may discuss lab concepts with other students. Please keep the Academic Integrity Policy in mind---do not show your code to anyone outside of the professors and tutors, and do not look at anyone else's code for this lab. If you need help, please post a question on Piazza, or contact the professor.

Concepts you will be familiar with after this lab include:

The video I recorded to explain this assignment is here.

Introduction

ASCII, ASCII art, ASCII animation

ASCII is an abbreviation for the American Standard Code for Information Interchange. In brief, the ASCII table picks a numeric representation for each of a set of characters; for instance, the letter 'A' is given the code 65, 'B' is 66, and '^' is 94. Text is stored in a computer as a sequence of numbers and then, when displayed, is translated from these numbers into visual representations of characters by tables like the ASCII table. Until recently, most text stored on computers was encoded in ASCII.

ASCII art is a term for the practice of using text to create images.

                 -===                    `"',
                ""o o                    O O|)   Going somewhere,
                _\ -/_                  _\o/ _        Solo?
               /| || |\                /|\ / |\
              //| || |\\              //| |  |\\
             || | || | \\            // | |  | ||
             || |/  \|  \\        -==#  | |  | ||
             |! |====|   ')         '\  |====| /#
             =] |/|| |                  | || | ''
              I ( )( )                  | || |
                |-||-|                  | || |
                | || |                  | || |
________________[_][__\________________/__)(_)_____________________

The use of printed text to form pictures is older than the ASCII standard. The term “ASCII art” gained popularity as the practice found its way onto computerized devices which used the ASCII table to standardize text representation. ASCIImation is the practice of using a repeated sequence of these textual images to create an animation using ASCII art. For this lab, you will be writing an ASCIImation player.

Input

The program should ask the user for the name of a file containing the data for the asciimation movie, then ask the user if they want to play the movie in reverse.

Output

The program should display the asciimation movie on screen, with each picture staying on screen the amount of time requested in the file. Naturally, if the user asked to play the movie in reverse, the animation should be played backwards.

The last frame of the asciimation should remain on screen at the end, and the program should print a quick message when it is about to end.

Specifics

Your program should first ask the user for the name of the animation file. Then, it should ask if the user wants to play the movie in reverse. Then, your program should read the appropriate movie file and play it, either as normal or in reverse. For instance, this command plays the smiley video:

$ python mgagnePrg4.py
animation file: smiley.asciimation
reverse list? no

The ASCIImation Format

The file asciimation.zip contains several ASCIImation files with the file extension .asciimation. These files contain the text representing different scenes in the animation.

Our animations will run at 15 frames per second; that is, your program will need to display a frame, wait for \(\frac{1}{15}\) of a second, and then clear the screen and display the next frame.

One way to accomplish this is to use the function

  time.sleep(numSec)
where numSec is the number of seconds to sleep (written as a float). To use this, you need to include the libraries time. For instance, time.sleep(1/15) will sleep for about $(\frac{1}{15})$ seconds. After sleeping, you can clear the screen using the following function that you should copy-paste in your code:
  from os import system, name
  def clearScreen(): 
      if name == 'nt': 
          _ = system('cls') 
      else: 
          _ = system('clear')
Note that this will only work in an actual terminal window, I will show you in lab how to run the program properly.

The .asciimation files themselves contain groups of 14 lines each. The first line of each group indicates a frame count while the remaining lines are the contents of the frame. (That is, each frame is 13 lines tall.) The frame count exists to reduce the size of the file, since we often want frames which do not change for a second or more. For instance, the following .asciimation file would display a smiley face for two seconds (30 frames). The smiley would then close its eyes for the next second (15 frames).

30
    ~~~~~~~~~~~~~~
   /              \
  /   ~_~    ~_~   \
 /    / \    / \    \
|    | * |  | * |    |
|     \_/    \_/     |
|                    |
|         ~~         |
|    \          /    |
 \    \________/    /
  \                /
   \              /
    --------------
15
    ~~~~~~~~~~~~~~
   /              \
  /   ~~~    ~~~   \
 /                  \
|    -===-  -===-    |
|                    |
|                    |
|         ~~         |
|    \          /    |
 \    \________/    /
  \                /
   \              /
    --------------

You should stop reading the asciimation file when you reach a line that should contain a frame count, but contains the string "XXXXX" (with a newline or not) instead. There may be other garbage in the file after that line, your program should not crash because of it.

Your code should include the following functions:

Using the Terminal

On a Windows computer:

Use the Windows explorer to go to the folder that contains your program, then press Ctrl-Shift-(right click) inside that folder. One of the options available there will be "Open PowerShell window here", select it and it should open the terminal. From there, the command to run your program will be "python <name of your program file here>". It should look something like this:

Windows PowerShell

On a Mac:

Click on the magnifying glass in the upper right corner of the screen and type "terminal", that will open the terminal. Then, you will need to move to the folder that contains your assignment. To do this, type the command "cd <new location>" where <new location> is the folder that is at the top of your Wing101 window when your file is open.

I read somewhere that you can also change the folder in a Mac terminal by dragging and dropping a folder from the Finder into the terminal, but I cannot test that at home, I will try it in class on Friday, let's consider that an unverified rumor for now.

On a Mac, the command to run your program will be "python3 <name of your program file here>" (note the command is python3 instead of python like it was on a Windows computer).

Notes

Like the previous assignment, your submitted assignment should start with a header containing the name of the author(s), filename, description of the program, input and output.

I recommend that you sketch a plan of the tests you intend to use before you start writing code, otherwise this could get messy. Five minutes of planning could save you an hour of debugging! You can also test your program by printing the result at the end of each step to see if each step is doing what you were expecting them to do (just remember to remove those prints before submitting the program).

Test your program carefully. You should try to have a test case that explores every possible "path" in your code, and think of special inputs that might cause problems.

The program is getting a little large now, so picking meaningful names for your variables will make the program that much easier to read and make all the information easier to access.

You can write more comments in your code to explain what is going on if you feel it is appropriate. It's never harmful to explain to the next person reading your code (or grading your code)

Acknowledgement

This lab write up is based off of the ASCIImation lab developped by the Computer Science Department of Swarthmore College.