Difference between revisions of "CSC111 Homework 12 2014"
(→Map-Digitizer Program) |
(→Map-Digitizer Program) |
||
Line 89: | Line 89: | ||
==Map-Digitizer Program== | ==Map-Digitizer Program== | ||
− | [[File:SmithMapSmall.gif| | + | [[File:SmithMapSmall.gif|210px|right]] |
<br /> | <br /> | ||
In case you want to digitize additional building from the Smith campus using the image to the right, you can use the program below. Read it well first to understand what it needs and what it generates. | In case you want to digitize additional building from the Smith campus using the image to the right, you can use the program below. Read it well first to understand what it needs and what it generates. |
Revision as of 20:39, 23 April 2014
--D. Thiebaut (talk) 20:06, 23 April 2014 (EDT)
The age of the Smith Buildings
Save the program below in a file in the same directory where you are developing hw12a.py, and call it buildingAges.py.
# 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
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
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"""
Map-Digitizer Program
In case you want to digitize additional building from the Smith campus using the image to the right, you can use 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
BurtonHall, 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, 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