我已经用johnzelle的教科书“Python编程”做了一些家庭作业。我使用一个图形库作为书的附加材料
我的问题是:我可以创建一个点的克隆,然后移动该克隆,然后再创建一个克隆(从该克隆)并移动该克隆吗
还是说“克隆人的克隆”是被禁止的,而我必须从原点创建第二个克隆人
谢谢你的帮助
源代码:
from graphics import * # import methods from graphis library
import math # import math library
def main():
# Create GraphWin, display instructions
win = GraphWin("Five-click house", 400,400) # Make sure GraphWin is large enough
win.setCoords(0,0,10,10) # The coordinate system should allow negative x and y values
# Draw the frame of the house
message = Text(Point(5,0.5), "Click at two point to define house frame")
message.draw(win)
P1 = win.getMouse()
P1.draw(win)
P2 = win.getMouse()
frame = Rectangle(P1,P2)
frame.draw(win)
# Draw door
MP = win.getMouse()
MP.draw(win)
width_frame = P2.getX() - P1.getX()
P3 = MP.clone()
P3.move(-((0.1)*width_frame),0)
P4 = MP.clone()
P4.move((0.1)*width_frame,0)
P5 = P4.clone()
h = P4.getY() - P1.getY()
P5.move(0,-h)
door = Rectangle(P3,P5)
door.draw(win)
# Draw Window
WC = win.getMouse() # WC: Window Center
P6 = WC.clone()
P6.move(-0.05*width_frame,0.05*width_frame)
P7 = WC.clone()
P7.move(0.05*width_frame,-0.05*width_frame)
wind = Rectangle(P6,P7)
wind.draw(win)
message.setText("Click to place the roof top")
# Draw top
HT = win.getMouse()
P8 = Point(P1.getX(), P2.getY())
top = Polygon(HT,P8,P2)
top.draw(win)
top.setFill("black")
# Exit with mouse click
win.getMouse()
win.close()
main()
这样做绝对没有问题,但很明显,当移动克隆点时,原始点仍将出现在其原始位置
相关问题 更多 >
编程相关推荐