CSC111 Homework 12 2014

From dftwiki3
Revision as of 08:42, 24 April 2014 by Thiebaut (talk | contribs) (Map-Digitizer Program)
Jump to: navigation, search

--D. Thiebaut (talk) 20:06, 23 April 2014 (EDT)




This assignment is due 5/1/14 evening, at midnight. You will need to submit your program and a copy of the map generated by the program, as a png or jpg file. You can work in pair-programming mode on this homework assignment.


Your Assignment


  • Your assignment is to generate a partial map of Smith with at least 15 buildings and color them according to their age.
Buildings built in 1700 to 1799 will be of a given color (your choice of color). Buildings built between 1800 and 1899 of a different color (your choice as well). Buildings built between 1900 and 1999 of a third color, and finally buildings built after 2000 in a fourth color. You can pick the colors, and they must all be different from each other.


  • Your program will display a legend on the image, made of 4 rectangles containing the 4 colors introduced above, and the year-range displayed next to them. You are free to organize the rectangles as you wish, either horizontally, or vertically, at the top of the map, bottom of the map, or on the sides of the map. If you're not sure what a legend looks like, take a look at a Google image search with the key terms "legend graph example".


  • Your program should be called hw12a.py.


  • Your program should contain the following statement at its top, right below the program header:


from buildingAges import buildingAgesText


(The details about the file buildingAgges.py are given below.)


  • You may use some of the buildings provided at the end of the page to get started, but you will have to add others. This list is provided AS-IS. You may use it or not.


  • Note that you should make sure that the way the buildings names are spelled out in your csv file matches the names found in the buildingAges.py file.


  • Your program should display your name or names at the bottom of the map, in a statement of the type "Map generated by Minnie Mouse and Pluto.".


  • Pick buildings for which we have a date of inauguration (not all buildings on campus are included in the list provided below).


  • Submit a copy of your map as hw12a.png, or hw12a.jpg, depending on how you capture the image.


Grading


  • Image submitted: 30 points
  • Program documentation & style: 30 points
  • Program correctness (colors, legend, at least 15 buildings, name at bottom) 40 points


Smith Buildings And Dates of Inauguration: buildingAges.py


Save the program below in a file called it buildingAges.py and put it in the same directory where you are developing your hw12a.py program.

# buildingAges.py
# D. Thiebaut
# A textual representation of the age the Smith buildings were erected.
#
buildingAgesText = """1710 Sessions House
1715 Drew Hall (cdo)
1810 Eleanor Duckett House
1810 Mary Ellen Chase House
1825 Capen Annex
1825 Capen House
1870 138 Elm
1872 Tyler Annex
1873 Sessions Annex
1875 College Hall
1877 Hatfield Hall
1878 Washburn House
1880 Park House
1881 Tenney House
1882 Pierce Hall
1883 10 Prospect Street
1884 150 Elm
1886 Lilly Hall
1886 Sunnyside-childcare Center
1890 76 Elm Street
1891 Alumnae Gymnasium
1892 Park Annex
1893 Lawrence House
1893 Morris House
1895 Lyman Plant House
1896 Parsons Annex
1898 Davis Center
1898 Tyler House
1899 Seelye Hall
1899 Stoddard Hall
1899 Wesley House
1900 Albright House
1900 Physical Plant
1903 Chapin House
1908 Baldwin House
1908 Clark Hall
1909 Morgan Hall
1909 Neilson Library
1909 Talbot House
1910 Gillett House
1910 John M. Greene Hall
1910 Northrop House
1911 Boat House
1914 Mendenhall Hall *
1918 Campus School-gill Hall
1919 Health Services-mason Infirmar
1919 Hopkins House
1920 Crew House
1920 Presidents House
1922 Ellen Emerson House
1922 Jordan House
1924 Sage Hall
1925 Riding Stables And Rings
1926 Cushing House
1926 Gardiner House
1926 Martha Wilson House
1926 Morrow House
1930 Comstock House
1930 Wilder House
1936 Franklin King House
1936 Laura Scales House
1938 Alumnae House
1955 Lamont House
1955 Ziskind House
1957 Cutter House
1961 Wright Hall
1972 Art Complex
1977 Ainsworth Gymnasium
1978 Friedman Complex
1985 Itt
2000 Bass Hall
2003 Campus Center
2009 Ford Hall
2014 Student Health and Wellness Center"""


Note: The actual date when the Mendenhall Center for the Performing Arts was erected is approximated. It was a gift from the class of 1914, but the actual year of its inauguration was not included in the orginal csv files obtained from Jon Caris.

Map-Digitizer Program

SmithMapSmall.gif


To digitize additional buildings from the Smith campus using the image on the right, you can use/edit/modify/get inspired by the program below. Read it well first to understand what it needs and what it generates.

# MapDigitizer.py
# D. Thiebaut
#
# This program imports the file SmithMapSmall.gif and displays it on the canvas.
# The user then must use the + symbol in the menu to start the digitization, which
# first asks the user to enter the name of the building.  The user then clicks on vertices
# of the building's outline to record their coordinates.  When the user has gone around the
# full building, she clicks on the minus symbol of the menu.   The program then writes the
# csv representation of the building to a file called buildings.csv.
#

from graphics111 import *

MAXWIDTH = 700    # the dimensions of the gif image
MAXHEIGHT = 836 

## call-back function.
# mouseEvent(): called by the graphics library whenever
# a mouse event is captured.
# win: a reference to the main graphics window
# canvas: a reference to the canvas
# x, y: the coordinates (in pixels) of the mouse click.
# (the top-left corner is 0,0)
def mouseEvent( win, canvas, x, y ):

    # global variables shared with main()
    global menu           # the menu top-left of the canvas
    global buildingList   # list of building coordinates
    global csvFileName    # name of the file where building csv info stored

    # ask menu is mouse was clicked on one of its buttons
    button = menu.buttonClicked( x, y )

    # mouse not clicked on menu item.  Add x, y coords to the
    # current building list.
    if button == None:
        buildingList.append( x )
        buildingList.append( y )
        
        # show some fun feedback for user
        if len( buildingList ) >=7 :
            canvas.setColor( 200, 130, 199 )
            canvas.drawPolygon( buildingList[1:] )
        
        return

    # nothing to do for left or right arrow
    if button == "LeftArrow" or button == "RightArrow":
        return

    # if plus button clicked, start a new list for a new
    # building.  Get a new name and start the list.
    if button == "Plus":
        rawName = input( "Building name? " ).strip()
        
        # capitalize the name
        name = ""
        for word in rawName.strip().split():
            name += word.capitalize()+ " "

        # start new list
        buildingList = [ name.strip() ]
        return    

    # if minus button, transform the list into csv line and
    # append to file.
    if button == "Minus":
        for i in range( 1, len( buildingList ) ):
            buildingList[i] = str( buildingList[i] )
        file = open( csvFileName, "a" )
        file.write( ", ".join( buildingList ) + "\n" )
        file.close()
        return


# ========================================================
#                       Main Program
# ========================================================
def main():
    # list of variables shared with the call-back function
    global menu
    global buildingList
    global csvFileName

    # the two files (located in same directory).
    # gif contains map, csv contains output of program
    csvFileName = "buildings.csv"        
    gifFileName = "SmithMapSmall.gif"
    
    # open the window and get access to its canvas
    win = GraphicsWindow(MAXWIDTH, MAXHEIGHT)
    canvas = win.canvas()
    canvas.setCallbackFunction( mouseEvent )

    # put gif image on canvas    
    photo = tk.PhotoImage( file=gifFileName )
    canvas._tkcanvas.create_image(0,0, image=photo, anchor = tk.NW )
    
    # add a menu to the window
    menu = Menu()
    menu.draw( canvas )
    
    # wait and respond to events, or comment out and make the program
    # stop as soon as car disappears.
    win.wait()
    win.close()
    
main()


Some Digitized Buildings


Note: all buildings are one-liners. Some lines are long and wrap, but the text below is really 8 lines long.

Ford Hall, 358, 493, 371, 490, 383, 485, 387, 492, 391, 491, 401, 517, 410, 518, 413, 528, 407, 532, 421, 579, 420, 584, 422, 593, 415, 595, 415, 602, 406, 604, 403, 600, 400, 597, 394, 600, 391, 596, 388, 596, 366, 529
Mendenhall Hall, 338, 497, 343, 512, 336, 512, 340, 522, 347, 520, 353, 543, 349, 546, 351, 556, 356, 556, 361, 572, 359, 583, 350, 581, 347, 576, 341, 577, 345, 594, 322, 601, 318, 595, 295, 599, 292, 598, 286, 597, 286, 601, 271, 606, 268, 600, 265, 585, 284, 581, 301, 574, 293, 532, 290, 529, 280, 529, 277, 515, 292, 511, 317, 503, 317, 498, 322, 496
Campus Center, 299, 125, 307, 115, 323, 117, 320, 124, 342, 126, 345, 119, 335, 93, 338, 88, 331, 87, 327, 77, 330, 70, 332, 52, 321, 49, 319, 59, 307, 55, 304, 65, 300, 66, 296, 96, 297, 104, 290, 106
Neilson Library, 354, 233, 371, 229, 373, 241, 377, 241, 379, 253, 385, 253, 389, 277, 403, 276, 412, 315, 403, 320, 404, 329, 410, 329, 407, 337, 399, 340, 399, 343, 393, 343, 393, 346, 399, 350, 400, 355, 380, 365, 381, 369, 387, 369, 388, 379, 383, 379, 390, 401, 393, 404, 393, 407, 391, 412, 373, 415, 363, 375, 375, 369, 349, 266, 360, 260
Wright Hall, 320, 214, 328, 242, 351, 239, 352, 249, 299, 263, 295, 247, 290, 246, 283, 234, 290, 226, 306, 225, 305, 214, 318, 214
Burton Hall, 269, 344, 256, 295, 235, 304, 242, 346, 251, 350
Sabin-reedHall, 221, 264, 198, 269, 223, 366, 244, 361, 244, 352, 234, 305, 233, 291, 229, 291
Seelye Hall, 463, 325, 470, 353, 478, 351, 477, 348, 482, 347, 486, 351, 492, 353, 495, 350, 497, 346, 498, 341, 503, 341, 505, 344, 514, 343, 507, 312, 497, 316, 497, 319, 475, 322, 470, 320



Submission