''' graphics1.py Jeff Ondich, 11 October 2018 Started in Pascal on 1/25/95 Ported to C++, Java, and Python Adapted to Python 3 by Jed Yang in 2016 1. Run it, and read all the functions to see what they do. 2. Try changing the parameters passed to say_hello(), say_hello_again(), draw_some_circles(). How do the parameters affect the picture? 3. Where is the origin (0,0) in the coordinate system of GraphWin? Are larger y values higher or lower on the screen? Are larger x values further right or further left on the screen? How can you tell? ''' from graphics import * def move_pen(window, pen, dx, dy, color): ''' Draws a line of the specified color from the Point pen to the Point (dx, dy) away from pen (where the variable names "dx" and "dy" are intended to evoke the "delta x" and "delta y" used in scientific notation). Once the line is drawn, move_pen changes the value of pen to equal the line's destination endpoint. For example, if pen = Point(10, 20), dx = 50, and dy = 80, then move_pen draws a line from Point(10,20) to Point(60, 100), and then sets pen equal to Point(60, 100) so further drawing can start from there. Note that since this function does not save the Line object it creates, there is no way to later un-draw the Line. ''' end_point = Point(pen.x + dx, pen.y + dy) line = Line(pen, end_point) line.setOutline(color) line.draw(window) # What happens if you comment out the next two lines? Why? pen.x = end_point.x pen.y = end_point.y # What happens if you comment out the previous two lines, and then uncomment # the following line? Why? # pen = end_point def say_hello(window, start_x, start_y): line_color = color_rgb(255, 0, 255) pen = Point(start_x, start_y) move_pen(window, pen, 30, -80, line_color) move_pen(window, pen, -10, -20, line_color) move_pen(window, pen, 0, 100, line_color) move_pen(window, pen, 10, -30, line_color) move_pen(window, pen, 10, 0, line_color) move_pen(window, pen, 10, 30, line_color) move_pen(window, pen, 15, 0, line_color) move_pen(window, pen, 10, -30, line_color) move_pen(window, pen, 5, 20, line_color) # Why do we create a new pen here? What's going on? pen = Point(pen.x - 10, pen.y - 40) move_pen(window, pen, 0, -10, line_color) def say_hello_again(window, x, y): text_color = color_rgb(255, 0, 0) text = Text(Point(x, y), 'Howdy') text.setTextColor(text_color) text.setSize(24) # What is the legal range of sizes? Can you omit this line? Why? text.setFace('helvetica') # Try changing 'helvetica' to 'courier' or omitting this line. text.draw(window) def draw_some_circles(window, y): circle_color = color_rgb(0, 0, 255) circle = Circle(Point(150, y), 50) circle.setOutline(circle_color) circle.draw(window) circle = Circle(Point(350, y), 50) circle.setFill(circle_color) circle.draw(window) def main(): # Open the window window_width = 600 window_height = 500 window = GraphWin('Graphics demo', window_width, window_height) background_color = color_rgb(0, 0, 0) window.setBackground(background_color) # Draw some things. draw_some_circles(window, 100) say_hello(window, 100, window_height - 100) say_hello_again(window, window_width - 250, window_height - 100) # Wait for user input. print('Click the window to quit') window.getMouse() # Which window? Why? main()