Introduction to Computer Science for Multidisciplinary Studies (CPSC 217) Exercise 6 of 8

University of Calgary Department of Computer Science

Introduction to Computer Science for Multidisciplinary Studies (CPSC 217) Exercise 6 of 8

This exercise is to be completed individually and is due on March 15, 2015.
Submit your solution as a Python source code file (i.e., a “.py” file) to the “Exercise 6 of 8” dropbox in D2L. Your source code must be commented. Uncommented submissions will be penalized.

Your .py file must be named with your last name, student number, and “Exercise6”, separated by underscores. e.g., Collier_12345678_Exercise6.py

For this exercise you will use SimpleGraphics to create an ASCII art generator – a program that will convert gif images into sequences of ASCII characters that, when printed to the console, approximate the original image. Your program will load an image (specified by the user), get the dimensions of that image, and then use two for loops to loop through the image and consider every pixel. Each pixel should be converted to a grayscale value and then, depending on how light (i.e., how close the gray value is to 255) the pixel is, print out a character of similar brightness (assuming the program is printing white text on a black background). To clarify, the “@” symbol in white, on a black background, appears brighter than the “.” symbol, so printing “@” is a good way to draw a white pixel, printing “.” is a good way to draw a dark (almost black) gray, etc. An example is included below:

..=:..,.,::=:,::=:::=:==::====::===:=~== .=.,…,:==,=:::==::~:====:::=::::==:=== =~….,,~~~:III==~=~=~:=~=~~:=~~=~~:~:=~ =:….:~=::,?III???~~~:~III=:=::==:=:=== ….,:===~.,I7777777777I+II=======:~~=:= ….==:,,,:~777I77I7III~=+?=:=======~==: ..,:=:::,,I7~~7IIIIIIII=+=+=======::=::: ..::::…:I7,,II~,,?III?II?=:=:=:::::,:: :=:,.:,,:=7I7==IIIIIIIIII+=::===:,:::,:= ::,.,,:::~?I==??+?I+??II?=::==::::=::=== ,.:,:::==~?+?I?+?=?+++??===:=~:::=:===== .,,:=~==::==I7?????++???I?:~===::====~~: ::~=:==:===?77II=++++?III??+======:===:: :===~===:==II7I7I?I?III?+I??~::::::::.., ~:=::=:====IIIIIII??I+?+?I?+=::::::=:::: :===:::,::=IIIIIII?III+I++I??+=::=:==::: :,:,,,:,::=II?III?+?I???+?+++?=====:==~= ~:~=====:~~?I+=?I?=~===?++=?=?====::::~~ ====:~.,.,=I7?~~?==~==?=++?==?==~:::==== ::,.,,,:::=?I+~~?==~=?+???====~,:,:::~~~ ::,::::,:,,?II~:=~::=??===~===:,::===~~~ =::::::::::?II~:.:,,?I??=~~==~::==~===:~ =:~=:=::==:?I+=:,:,.I7?+==?=,.,:::~:==== ===:====:=II??~,,…II??~+.,,:=:==~=::== ===~~==::===?=,,:::??+??:::~============ ~=::=~===~====~::~~:+?~:~===~=~~~:~~:::: =:::=====:~==:===:::==:==::=::~::,::~:~~ =====:==:::==:::=::===~~:::::,::::~:===~ ::::=:===:=::=:==:=:::::::::::~~=:=:::::

To achieve a mark of 50% for this exercise, your program must:

  •   prompt the user for the name of the file to be converted (n.b., assume the image width is 60)
  •   print an ASCII art representation of this image using at least 10 different characters as colours

    To achieve a mark of 100% for this exercise, your program must also:

  •   ask the user whether the terminal is black or white and adjust accordingly
  •   work for images where the image width is between 10 and 80 pixels

    Do not upload image files unless you have permission from your instructor to use images other than those provided.