0

i1 = pd.self.r1
i2 = pd.self.b1
if(i1.overlaps(i2)): 
   self.create_canvas.move(self.b1, 135, 250)

Here self.r1,self.b1 are different color coin r1 is red's 1st coin similarly b1 is for blue This is just the part of code where I'm stuck.

I want to check whether the previous coin and the coin which moved now overlap. If they overlap, then the previous coin must move to its box back.

for more please view the code here :- click here

Suraj
  • 41
  • 6
  • whoever is not able to find the code of my whole program please click on this link :- https://codefile.io/f/7DOEp5U0b6QN1N7Dv0jd – Suraj Nov 10 '22 at 08:01
  • If you want to see if 2 circles overlap: `(circle_a.x-circle_b.x)**2 + (circle_a.y-circle_b.y)**2 <= circle_a.radius + circle_b.radius` – TheLizzard Nov 10 '22 at 10:54
  • Please provide enough code so others can better understand or reproduce the problem. – Community Nov 10 '22 at 19:59
  • @TheLizzard since the circles have been created using tkinter oval so the circle doesn't have any radius. that's the problem – Suraj Nov 11 '22 at 07:47
  • @Suraj You created the circles so you can keep track of their radius. – TheLizzard Nov 11 '22 at 10:20
  • @TheLizzard I created the circle using the oval function which doesn't asked for any radius. – Suraj Mar 18 '23 at 08:22
  • @Suraj `create_oval` method takes in 4 coordinates. If they are circles instead of ovals, you must be able to find the radius of the circles from your `.create_ovel` code. Like look [here](https://stackoverflow.com/a/54039472/11106801) - in that case `r` is the radius. If you edit your question with the code that creates the circles, I will be able to work out the radius for you. – TheLizzard Mar 19 '23 at 13:04
  • @TheLizzard its in the 1226th line the first cirle that's red I may type it for you, the following is the code for red circle:- self.create_canvas.create_oval(67, 58, 91, 83, width=3, fill="#ff0000", activewidth=4, activefill="#ff0000") and Thanks a lot for your help – Suraj Mar 19 '23 at 13:50
  • @Suraj That is not a perfect circle. It's radius is 12 in the x-axis and 12.5 in the y-axis. The easiest solution is to take the radius as 12. If that doesn't look right, you might need to use 15 or 16 because of the `width` – TheLizzard Mar 19 '23 at 14:25
  • @TheLizzard I've total of 16 circles it would be difficult for me to give random radius to each one of them by considering approximation. – Suraj Mar 20 '23 at 12:40

0 Answers0