# c04ex11.pyw

c04ex11.pyw

build a house with 5 mouse clicks

from graphics import *

def main():
win = GraphWin("Design a House",500,500)
win.setCoords(0, 0, 200, 200)
message = Text(Point(100,5),"")
message.draw(win)

# Draw the frame of the house
message.setText("Click on lower left corner of the frame")
frameLL = win.getMouse()
frameLL.draw(win)
message.setText("Click upper right corner of the frame")
frameUR = win.getMouse()
frameLL.undraw()
Rectangle(frameLL, frameUR).draw(win)

# Draw a door
houseWidth = frameUR.getX() - frameLL.getX()
doorWidth = 0.2 * houseWidth
halfDoor = doorWidth/2.0
message.setText("Click on the center of the top of the door")
doorPt2 = win.getMouse()
doorPt2.move(halfDoor, 0)
doorX1 = doorPt2.getX() - doorWidth
doorY1 = frameLL.getY()
door = Rectangle(Point(doorX1,doorY1), doorPt2)
door.setFill("red")
door.draw(win)

# Draw a window
message.setText( "Click on the center of the window")
windowCenter = win.getMouse()
w1 = windowCenter.clone()
winOff = 0.5 * halfDoor
w1.move(-winOff,winOff)
w2 = windowCenter.clone()
w2.move(winOff, -winOff)
Rectangle(w1,w2).draw(win)

# Draw the roof
message.setText( "Click on the peak of the roof")
peak = win.getMouse()
frameUL = frameUR.clone()
frameUL.move(-houseWidth,0)
roof = Polygon(frameUL, peak, frameUR)
roof.draw(win)
roof.setFill("black")

message.setText( "Click anywhere to quit." )
win.getMouse()
win.close()

main()

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 12,164评论 0 10
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,771评论 19 139
  • ¥开启¥ 【iAPP实现进入界面执行逐一显】 〖2017-08-25 15:22:14〗 《//首先开一个线程,因...
    小菜c阅读 11,840评论 0 17
  • 人生处处早, 易显乾坤事, 山水自震坎, 连山起归藏。
    三径堂阅读 1,365评论 0 0
  • 回到住所,翻看了一天都没有看的微信朋友圈,看到她的心情上写着,大概的意思就是这样,“最后一天在这里上班了,我还可以...
    雨纹阅读 2,629评论 0 0