CSC111 Homework 12 2014
--D. Thiebaut (talk) 20:06, 23 April 2014 (EDT)
Map-Digitizer Program
# Demo program for resizing a graphic object.
# D. Thiebaut
#
from graphics111 import *
MAXWIDTH = 800
MAXHEIGHT = 800
## 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
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