Difference between revisions of "CSC111 lab 5 Solution Programs 2011"
(Created page with "--~~~~ ---- <onlydft> <br /> <source lang="python"> from graphics import * def taxi(): win = GraphWin( "TAXI", 800, 600 ) # body of car rect = Rectangle(Point (2...") |
|||
Line 2: | Line 2: | ||
---- | ---- | ||
− | + | ||
<br /> | <br /> | ||
<source lang="python"> | <source lang="python"> | ||
Line 126: | Line 126: | ||
</source> | </source> | ||
<br /> | <br /> | ||
− | + | ||
<br /> | <br /> | ||
Latest revision as of 15:51, 6 October 2011
--D. Thiebaut 17:00, 5 October 2011 (EDT)
from graphics import *
def taxi():
win = GraphWin( "TAXI", 800, 600 )
# body of car
rect = Rectangle(Point (225, 250), Point(575, 350))
rect.setFill('yellow')
rect.draw(win)
# top of car
rect2 = Rectangle(Point (300, 175), Point (500, 250))
rect2.setFill('yellow')
rect2.draw(win)
# left window
rect3 =Rectangle(Point(310, 180), Point( 390, 240 ) )
rect3.setFill('white')
rect3.draw(win)
# right window
rect4 =Rectangle( Point(410, 180), Point( 492, 242) )
rect4.setFill('white')
rect4.draw(win)
# label in middle of body of car
center = Point(400, 300)
label = Text ( center, "TAXI")
label.draw(win)
# wheels
ccenter1 = Point(300, 350)
ccenter2 = Point(500, 350)
wheel1 = Circle(ccenter1, 50)
wheel1.setFill('black')
wheel1.draw(win)
wheel2 = Circle(ccenter2, 50)
wheel2.setFill('black')
wheel2.draw(win)
# keep window up until user presses Enter key
Text( Point( 400, 550 ), "Click me to close me!" ).draw( win )
win.getMouse()
win.close()
def main():
width = 800
height = 600
win = GraphWin( "lab 5", width, height )
# draw a taxi cab in its own window
taxi()
# circles...
c = Circle( Point( 50, 60 ), 20 )
c.draw( win )
c = Circle( Point( 50+100, 60 ), 20 )
c.draw( win )
c = Circle( Point( 50+200, 60 ), 20 )
c.draw( win )
Text( Point( width/2, height*7/8 ), "Click me to continue" ).draw( win )
win.getMouse()
# loop with circles
for i in range( 0, 800, 100 ):
c = Circle( Point( 50+i, 60 ), 20 )
c.setFill( "yellow" )
c.draw( win )
win.getMouse()
# diagonal of circles
for i in range( 0, 800, 100 ):
c = Circle( Point( 50+i, 60+i ), 20 )
c.setFill( "orange" )
c.draw( win )
win.getMouse()
# 5 lines of 8 circles
for i in range( 0, 800, 100 ):
for j in range( 0, 500, 100 ):
c = Circle( Point( 50+i, 60+j ), 20 )
c.setWidth( 3 )
c.setFill( "magenta" )
c.draw( win )
win.getMouse()
win.close()
#--- open a new window ---
width = 200
height= 200
win = GraphWin( "Diagonals", width, height )
# Lines: diagonals
line = Line( Point( 0, 0 ), Point( width, height ) )
line.draw( win )
line = Line( Point( 0, height ), Point( width, 0 ) )
line.draw( win )
msg1 = Text( Point( width/2, height*7/8 ), "Click me to continue" )
msg1.draw( win )
win.getMouse()
# Lines: 45-degree lines
for i in range( 10, 100, 10 ):
line = Line( Point( 10, i ), Point( i, 10 ) )
line.draw( win )
msg1.undraw()
msg2 = Text( Point( width/2, height*7/8 ), "Click me to close" )
msg2.draw( win )
win.getMouse()
win.close()
main()