Contents

  1. graphics_test.py
  2. rectangle.py

graphics_test.py 1/2

[
top][prev][next]
# Demonstrate use of graphics library

from graphics import *

win = GraphWin("My Circle", 500, 500)
point = Point(50, 50)
c = Circle(point, 10)
c.draw(win)

# making my own color
myDarkBlueGreen = color_rgb(10,100,100)
# set the window background to that color
win.setBackground(myDarkBlueGreen)

# pause, hold the picture
win.getMouse()

# change the background
win.setBackground("blue4")
win.getMouse()


rectangle.py 2/2

[
top][prev][next]
# Practicing drawing rectangles
# by CSCI111

from graphics import *

# Construct the graphics window
win = GraphWin("My Rectangle")

# Construct the rectangle
upLeft = Point(0, 0)
lowRight = Point(100, 120)

rect = Rectangle( upLeft, lowRight)
rect.setFill("pink")

# Move the rectangle to the right 10 pixels
rect.move(10, 0)

# Draw the rectangle, then pause
rect.draw(win)
win.getMouse()

# Move the rectangle down 10.5 pixels, then pause
rect.move(0, 10.5)
win.getMouse()

# What are the new coordinates of the upperleft corner of the rectangle?
newUpLeft = rect.getP1()

xcoord = newUpLeft.getX()
ycoord = newUpLeft.getY()

# Alternative way to write: 
# newUpLeftYCoord = rect.getP1().getY()

print "The upperleft point's coordinates are (", xcoord, ycoord, ")"









Generated by GNU enscript 1.6.4.