Difference between revisions of "CSC111 Final Exam 2015"
Line 18: | Line 18: | ||
<br /> | <br /> | ||
[[Image:frog3.gif|right]] | [[Image:frog3.gif|right]] | ||
− | You can use the frog image on the right for your game, or use one you will have found on the Web. Or you can draw it using ovals and/or circles. The URL for the image on the right is: | + | You can use the frog image on the right for your game, or use one you will have found on the Web. Or you can draw it using ovals and/or circles. The URL for the image on the right is: http://cs.smith.edu/dftwiki/images/f/f6/Frog3.gif |
+ | <br /> | ||
+ | ==The Banner== | ||
+ | <br /> | ||
+ | The banner at the top of the screen is an object of the class given below. | ||
+ | <br /> | ||
+ | ::<source lang="python"> | ||
+ | class Banner: | ||
+ | def __init__( self, message ): | ||
+ | self.text = Text( Point( WIDTH//2, 20 ), message ) | ||
+ | self.text.setFill( "black" ) | ||
+ | self.text.setTextColor( "black" ) | ||
+ | self.text.setSize( 20 ) | ||
+ | |||
+ | def draw( self, win ): | ||
+ | self.text.draw( win ) | ||
+ | self.win = win | ||
+ | |||
+ | def setText( self, message ): | ||
+ | self.text.setText( message ) | ||
+ | |||
+ | </source> | ||
+ | <br /> | ||
+ | An example of how to use it is illustrated below: | ||
+ | <br /> | ||
+ | ::<source lang="python"> | ||
+ | # bannerDemo.py | ||
+ | # D. Thiebaut | ||
+ | # A short program illustrating the use of a banner in | ||
+ | # graphics. | ||
+ | from graphics import * | ||
+ | WIDTH=800 | ||
+ | HEIGHT=600 | ||
+ | |||
+ | class Banner: | ||
+ | def __init__( self, message ): | ||
+ | """constructor. Creates a message at the top of the graphics window""" | ||
+ | self.text = Text( Point( WIDTH//2, 20 ), message ) | ||
+ | self.text.setFill( "black" ) | ||
+ | self.text.setTextColor( "black" ) | ||
+ | self.text.setSize( 20 ) | ||
+ | |||
+ | def draw( self, win ): | ||
+ | """draws the text of the banner on the graphics window""" | ||
+ | self.text.draw( win ) | ||
+ | self.win = win | ||
+ | |||
+ | def setText( self, message ): | ||
+ | """change the text of the banner.""" | ||
+ | self.text.setText( message ) | ||
+ | |||
+ | def main(): | ||
+ | # creates a window | ||
+ | win = GraphWin( "Demo", WIDTH, HEIGHT ) | ||
+ | |||
+ | # draw the banner at the top | ||
+ | banner = Banner( "Demo. Please click the mouse!" ) | ||
+ | banner.draw( win ) | ||
+ | |||
+ | # wait for the user to click the mouse before continuing... | ||
+ | p = win.getMouse() | ||
+ | |||
+ | # update the banner | ||
+ | banner.setText( "Mouse clicked at Point({0:1}, {1:1})" | ||
+ | .format( p.getX(), p.getY() ) ) | ||
+ | |||
+ | # wait again, and update the banner one more time | ||
+ | p = win.getMouse() | ||
+ | banner.setText( "Mouse clicked again, at Point({0:1}, {1:1})" | ||
+ | .format( p.getX(), p.getY() ) ) | ||
+ | |||
+ | win.getMouse() | ||
+ | win.close() | ||
+ | |||
+ | main() | ||
+ | |||
+ | </source> | ||
+ | <br /> | ||