Dec-23-2017, 03:48 AM
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:
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()?
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()?