我可以创建克隆的克隆吗?

时间:2019-04-10 12:17:31

标签: python

我在John Zelle的教科书“ Python编程”中做了一些功课。我使用图片库作为本书的其他材料。

我的问题:我可以创建一个Point的克隆,然后移动该克隆,然后再从该克隆中创建一个克隆并移动该克隆吗?

还是禁止“克隆克隆”,我必须从原点创建第二个克隆?

感谢帮助!

源代码:

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()

1 个答案:

答案 0 :(得分:0)

这样做绝对没有问题,但是很明显,当您移动克隆点时,原始点仍将出现在其原始位置。