-
Notifications
You must be signed in to change notification settings - Fork 3
/
balling ball.py
51 lines (38 loc) · 939 Bytes
/
balling ball.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
43
44
45
46
47
48
49
50
51
import turtle
import random
var1=turtle.Screen()
var1.title('Boucing ball')
var1.bgcolor('black')
listball=[]
color=['red','yellow','blue','green','white','pink']
shape=['circle']
for i in range(5):
listball.append(turtle.Turtle())
for ball in listball:
ball.shape(random.choice(shape))
ball.color(random.choice(color))
ball.penup()
x=random.randint(-280,280)
ball.goto(x,200)
ball.dx=1.5
ball.dy=0
v=random.randint(0,30)
gravity=2
while True:
for ball in listball:
ball.dy-=gravity
y=ball.ycor()
ball.sety(y+ball.dy)
ball.setx(ball.xcor() + ball.dx)
if(ball.ycor()<-280):
ball.rt(v)
ball.dy*=-1
if(ball.ycor()>200):
ball.rt(v)
ball.dy *= -1
if(ball.xcor()<-300):
ball.rt(v)
ball.dx*=-1
if (ball.xcor() >300):
ball.rt(v)
ball.dx *= -1