Contents
- ./graphics_test.py
- ./rectangle.py
./graphics_test.py 1/2
[top][prev][next]
# Demonstrating the graphics library
# by Sara Sprenkle
from graphics import *
win = GraphWin("My Circle", 200, 200)
point = Point(100,100)
c = Circle(point, 10)
c.setFill("red") # make it a red circle
c.draw(win)
#c.setOutline(color_rgb(200, 0, 200)) #give the circle a pretty fucshia outline
#c.setWidth(3) # make its outline wider
#point.draw(win) # in original code, the center point is not drawn
# If you want to see the point, you can!
# demonstrate what happens, outside of IDLE, if the line below is commented out.
win.getMouse()
win.close()
./rectangle.py 2/2
[top][prev][next]
# Draw a rectangle using the graphics API
# by CSCI111
from graphics import *
# Create a window
window = GraphWin("My Rectangle", 200, 200)
# Create an instance of a rectangle that is blue and 50x100
# pixels in the upper left of the window
upper_left_point = Point(0, 0)
lower_right_point = Point(50, 100)
my_rectangle = Rectangle(upper_left_point, lower_right_point)
# alternatively, could have created the rectangle in a single, messier,
# harder-to-debug statement
# my_rectangle = Rectangle( Point(0,0), Point(50,100) )
my_rectangle.setFill("blue")
# draw the rectangle
my_rectangle.draw(window)
# pause so we can see the rectangle shift
window.getMouse()
# shift the instance of the rectangle to the right 10 pixels
my_rectangle.move(10, 0)
# find out the x- and y-coordinates of the
# upper-left corner of the rectangle
new_upper_left_point = my_rectangle.getP1()
new_upper_left_x = new_upper_left_point.getX()
new_upper_left_y = new_upper_left_point.getY()
# When you run the program, note the output
# this one prints out the _Point_ object
print("The new upper left point is", new_upper_left_point)
# these print out the integers for the x and y coordinates, respectively
print("The new upper left point's x is", new_upper_left_x)
print("The new upper left point's y is", new_upper_left_y)
# this one prints out the point's coordinates in my own desired format.
print("The new upper left point's coordinates are (", new_upper_left_x, ",", new_upper_left_y, ")")
# pause so that the window doesn't close before we want it to close
window.getMouse()
window.close()
Generated by GNU Enscript 1.6.5.90.