![]() |
Updating Point Graphics Coordinates - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Updating Point Graphics Coordinates (/thread-7147.html) |
Updating Point Graphics Coordinates - pi314159geek - Dec-23-2017 In my program, I create a circle called "electron" at a random place. I then draw a second circle called "photon", that starts at a constant place (-555, -555). The photon moves toward the electron. I want the photon to stop moving and disappear when it's directly on top of the electron. I found the x- and y-coordinates of the two circles' centers, and compared their values to find when the electron was on top of the photon. Below is my attempt: movephoton = True while movephoton: photon.move(P_to_R/P_to_E, E_to_R/P_to_E) #P_to_R, P_to_E, and E_to_R are all distances that depend on the angle of the electron to the photon. Their values are randomized by the program. time.sleep(0.01) if photon_center.getX() < electron_center.getX(): #photon_center and electron_center are just the center points of the photon and electron movephoton = True else: movephoton = FalseThe photon moves in the right direction, directly toward the electron. However, the photon moves right past the electron and continues off the window. I tried printing the photon center point's getX and getY, moving the photon a short distance, and printing getX and getY again. It just prints (-555, -555) every time, even though the photon itself has moved. How do I make the graphics point coordinates update continuously? Thanks! Edit, I found the problem. I was treating photon_center as a dynamic variable, when actually I'd set the specific coordinates (-555, -555), so it wasn't updating as the photon moved. So I used the circle.getCenter() command. However, there's a new problem with this. How do I isolate the x-coordinate of the point retrived by circle.getCenter()? RE: Updating Point Graphics Coordinates - squenson - Dec-23-2017 We cannot answer your question without having the code of the class circle .
RE: Updating Point Graphics Coordinates - pi314159geek - Dec-23-2017 I'm not sure I understand the question. "Circle" isn't a class; it's just the name for the object in the graphics window. RE: Updating Point Graphics Coordinates - Windspar - Dec-24-2017 It would help to know if you are using any libraries ? Quote:However, there's a new problem with this. How do I isolate the x-coordinate of the point retrived by circle.getCenter()?assume it a tuple/list length 2. x, y = circle.getCenter() # or x = circle.getCenter()[0] |