###################################################################### # # graphics1.py # # Started in Pascal by Jeff Ondich on 1/25/95 # Ported to C++, Java, and Python # Last modified 1/19/07 # # 1. Run it, and read all the functions to see what they do. # # 2. Try changing the parameters passed to sayHello(), sayHelloAgain(), # sayHelloAgain(), and drawSomeCircles(). 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 drawLine(window, x1, y1, x2, y2, color): firstPoint = Point(x1, y1) secondPoint = Point(x2, y2) line = Line(firstPoint, secondPoint) line.setOutline(color) line.draw(window) def sayHello(window, startX, startY): lineColor = color_rgb(255, 255, 255) x1, y1 = startX, startY x2, y2 = startX + 30, startY - 80 drawLine(window, x1, y1, x2, y2, lineColor) x1, y1 = x2 - 10, y2 - 20 drawLine(window, x1, y1, x2, y2, lineColor) x2, y2 = x1, y1 + 100 drawLine(window, x1, y1, x2, y2, lineColor) x1, y1 = x2 + 10, y2 - 30 drawLine(window, x1, y1, x2, y2, lineColor) x2, y2 = x1 + 10, y1 drawLine(window, x1, y1, x2, y2, lineColor) x1, y1 = x2 + 10, y2 + 30 drawLine(window, x1, y1, x2, y2, lineColor) x2, y2 = x1 + 15, y1 drawLine(window, x1, y1, x2, y2, lineColor) x1, y1 = x2 + 10, y2 - 30 drawLine(window, x1, y1, x2, y2, lineColor) x2, y2 = x1 + 5, y1 + 20 drawLine(window, x1, y1, x2, y2, lineColor) x1, y1 = x2 - 10, y2 - 40 x2, y2 = x1, y1 - 2 drawLine(window, x1, y1, x2, y2, lineColor) def sayHelloAgain(window, x, y): textColor = color_rgb(255, 0, 0) text = Text(Point(x, y), 'Howdy') text.setTextColor(textColor); text.setSize(24) text.draw(window); def drawSomeCircles(window, y): circleColor = color_rgb(0, 0, 255) circle = Circle(Point(150, y), 50) circle.setOutline(circleColor) circle.draw(window) circle = Circle(Point(350, y), 50) circle.setFill(circleColor) circle.draw(window) # All the functions are defined. Now start doing stuff. # Open the window windowWidth = 600; windowHeight = 500; window = GraphWin('Graphics demo', windowWidth, windowHeight) backgroundColor = color_rgb(0, 0, 0) window.setBackground(backgroundColor); # Draw some things. drawSomeCircles(window, 100); sayHello(window, 100, windowHeight - 100); sayHelloAgain(window, windowWidth - 250, windowHeight - 100); # Wait for user input. s = raw_input('Hit Enter to quit')