Question: Write a function to meet this specification. on python moveTo(shape, newCenter), shape is a graphics object that supports the getCenter method and newCenter is a
Write a function to meet this specification. on python
moveTo(shape, newCenter), shape is a graphics object that supports the getCenter method and newCenter is a Point. Moves shape so that newCenter is its center.
Use your function to write program that draws a circle and then allows the user to click the window 10 times. Each time the user clicks, the circle is moved where the user clicked.

def moveTo(shape, newCenter): oldCenter = shape.getCenter() myOldX, myOldY = oldCenter.getX(), oldCenter.getY() myNewX, myNewY = newCenter.getX(), newCenter.getY() moveX = myNewX - myOldX moveY = myNewY - myOldY shape.move(moveX, moveY) return shape
def main(): win = GraphWin("My Graph Win", 500, 500) win.setBackground("white") win.setCoords(0, 0, 10, 10) Text(Point(5, 8.5), "Please click 10 times.").draw(win) myPoint = win.getMouse() myX, myY = myPoint.getX(), myPoint.getY() myShape = Circle(myPoint, 2) myShape.draw(win)
for x in range(1, 10): newCenter = win.getMouse() myShape = moveTo(myShape, newCenter)
win.close()
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
