Contents

  1. ./graphics_test.py
  2. ./rectangle.py

./graphics_test.py 1/2

[
top][prev][next]
# Graphics Test Script
# by Sara Sprenkle

from graphics import *

win = GraphWin("My Circle", 200, 200)
point = Point(100,100)
c = Circle(point, 10)
c.draw(win)

#c.setFill("yellow") # make it a yellow circle
#c.setOutline(color_rgb(200, 0, 200)) #give the circle a pretty fucshia outline
#c.setWidth(3) # make its outline wider

# 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 *

win = GraphWin("My Rectangle")

# create an instance of a Rectangle that is 50 x 100 pixels 
# in the upper left of the window
upperLeftPoint = Point(0,0)
lowerRightPoint = Point(50, 100)
rectangle = Rectangle( upperLeftPoint, lowerRightPoint )

# draw the rectangle
rectangle.draw(win)

# pause so we can see the rectangle
win.getMouse()

# shift the instance of the Rectangle class to the right 10 pixels
rectangle.move(10, 0)
win.getMouse()

# find the x- and y- coordinates of the upper-left corner of the rectangle
upperLeftPoint = rectangle.getP1()
xcoord = upperLeftPoint.getX()
ycoord = upperLeftPoint.getY()
print("the upper left point is now at", xcoord, ",", ycoord)


win.getMouse()
win.close()

Generated by GNU Enscript 1.6.5.90.