How to move each figure toward the goal between the poin that I click on graphics and the center of my object in Python
Each time, the figure should move 1/16 of its current distance from the goal (the distance gets smaller each time).
Thanks!!!!!!!!!
for i in range(len(aaa)):
midxtoptx = pt.getX() - midptslist[i].getX()
midytopty = pt.getY() - midptslist[i].getY()
moveAll(aaa[i], midxtoptx/16, midytopty/16)
len(aaa) means the number of figures that I going to draw on the graphics and the number is inputed by the user midptslist is the center point of all my objects in Canvas. These objects are determined by the two clicks on the Canvas. Also, I adjust the size of my objects (which I use scale) in to the area determined by the two points. Also, the number o开发者_如何学运维f len(aaa) is the same as midptslist.
pt.getX() or Y() = the goal point that I want to move to from the center of my objects. Now, my question is that how to change the midptslist to the position right after every move because I always need the 1/16 of the remaining distance in order to calculate the movement?
Please help!!!!!!
def move(obj, goal):
obj.x = ((obj.x - goal.x) * 15.0 / 16) + goal.x
obj.y = ((obj.y - goal.y) * 15.0 / 16) + goal.y
Here's how to think of it:
|========|--------------| 0 goal obj |--------------| subtract ======= 0 obj |------------| multiply and divide 0 obj |========|------------| add back ======= 0 goal obj
Result: obj is a little closer to goal. Also works if obj is to the left of goal.
精彩评论