Python Forum
Updating Point Graphics Coordinates
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Updating Point Graphics Coordinates
#1
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 = False
The 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()?
Reply
#2
We cannot answer your question without having the code of the class circle.
Reply
#3
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.
Reply
#4
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]
99 percent of computer problems exists between chair and keyboard.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python graphics kaltenherz 1 1,713 Sep-05-2021, 05:19 PM
Last Post: jefsummers
  connecting the first point to the last point Matplotlib omar_mohsen 0 4,579 Jan-15-2020, 01:23 PM
Last Post: omar_mohsen
  from graphics import * jmaloney413 2 5,199 Oct-18-2018, 08:22 AM
Last Post: perfringo
  Graphics py not found vnc 13 22,355 Apr-05-2017, 05:36 PM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020