CPSC 110 - Section 05 Spring 08
From MWCSWiki
Page Is Unavailable Due To Site Maintenance, Please Visit Reserve Copy Page
Information for students in CPSC 110 - Section 05
- Introducing Python video - http://paprika.umw.edu/~ernie/cpsc110/IntroducingPython.mpg
- Download python for your computer - http://python.org/download/
- Group 1: Placing text on the page
- win = GraphWin("draw a house", 400, 400)
- win.setCoords(0.0,0.0,10.0,10.0)
- TextLL = Point(1.0, 0.5)
- then before each component of the house code, type-
- Text(textLL, "draw a house")
- Text (textLL, "draw a window")
Group 2: Draw a square using a rectangular object(the house!)
p1 = win.getMouse()
p1.draw(win)
p2 = win.getMouse()
p2.draw(win)
rect = Rectangle(p1, p2)
rect.setFill("brown")
rect.setOutline("brown")
rect.draw(win)
group 3: making the door
#click 3 yeilds the center of the top of the door
#prompt the user for the top center of the door
message.setText("Where do you want the top center of the door to be?")
p3 = win.getMouse()
p3.draw(win)
#house width is the horizontal distance between p1 and p2
house_width = (abs(p1.getX() - p2.getX()))
#door width is a fifth of the house width
door_width = house_width / 5
#window width is half the door's width
window_width = door_width / 2
#determine coordinates for upper left and lower right corners of door
#a coordinates are the upper left, b are the lower right
xa = p3.getX() - door_width / 2
xb = p3.getX() + door_width / 2
ya = p3.getY()
yb = p1.getY()
#once coordinates are determined, assign them to rectangular object, door
door = Rectangle(Point(xa,ya), Point(xb, yb))
door.setFill('white')
#draw the object, door
door.draw(win)
Group 4: Draw a square window that is (in our case) one-tenth the width of the house on all sides. The click for the window should be the center of the window.
widthRoom = abs(p2.getX() - p1.getX()) halfWindow = widthRoom / 20 p3 = win.getMouse() x1 = p3.getX() - halfWindow x2 = p3.getX() + halfWindow y1 = p3.getY() - halfWindow y2 = p3.getY() + halfWindow p4 = Point(x1, y1) p5 = Point(x2, y2) window = Rectangle(p4, p5) window.draw(win)
I will update this later after Group 3 has posted their code.
______________________________________________
p5 = win.getMouse()
p5.draw(win)
triangle = Polygon(p5, p1, Point(p2.getX(), p1.getY()))
triangle.setFill("brown")
triangle.Outline("brown")
triangle.draw(win)

