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 *

# create my canvas
canvas = GraphWin("Moving Rectangle", 200, 200)

# create the rectangle
upperLeftPoint = Point(50, 50)
lowerRightPoint = Point(150, 150)
rectangle = Rectangle(upperLeftPoint, lowerRightPoint)

# Alternative, not recommended approach: 
# rectangle = Rectangle( Point(50, 50), Point(100, 100) )

rectangle.setFill("purple3") # let's make it a dark purple

# draw it

rectangle.draw(canvas)
canvas.getMouse()

# shift it to the right 10 pixels

rectangle.move(10, 0)
# 
canvas.getMouse()

# find out the x and y coordinates of the upper left corner
newUpperLeftPoint = rectangle.getP1()
newLowerRightPoint = rectangle.getP2()

print("coordinate of upper left point:", newUpperLeftPoint)
print("coordinate of lower right point:", newLowerRightPoint)

# How would I get just the X coordinate of the upper left point?

canvas.getMouse()
canvas.close()

Generated by GNU Enscript 1.6.6.