-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcollide.py
42 lines (32 loc) · 992 Bytes
/
collide.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# To change this template, choose Tools | Templates
# and open the template in the editor.
__author__="karlo"
__date__ ="$Jun 5, 2011 3:54:04 PM$"
from gasp import *
def distance(x1, y1, x2, y2):
return ((x2 - x1)**2 + (y2 - y1)**2)**0.5
def collide():
begin_graphics(800, 600, title="Catch", background=color.YELLOW)
set_speed(120)
ball1_x = 10
ball1_y = 300
ball1 = Circle((ball1_x, ball1_y), 10, filled=True)
ball1_dx = 4
ball2_x = 790
ball2_y = 300
ball2 = Circle((ball2_x, ball2_y), 10)
ball2_dx = -4
while ball1_x < 810:
ball1_x += ball1_dx
ball2_x += ball2_dx
move_to(ball1, (ball1_x, ball1_y))
move_to(ball2, (ball2_x, ball2_y))
if distance(ball1_x, ball1_y, ball2_x, ball2_y) <= 20:
remove_from_screen(ball1)
# remove_from_screen(ball2)
# break
update_when('next_tick')
sleep(1)
end_graphics()
if __name__ == "__main__":
collide()