loading
main.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
import turtle
import random
import math
screen = turtle.Screen() 
screen.bgcolor('black')


#Ball location (Global)
ballX=0
ballY=0
dX= random.randint(-5,5)
dY= random.randint(-5,5)
ball = turtle.Turtle()
distance=100
corner=False

def setupBall():
  global ball
  global ballX
  global ballY
  ball.shape('circle')
  ball.speed(0)
  ball.color('blue')
  ball.penup()
  ball.goto(ballX,ballY)
  print(dX,dY)

def animate():
  global ball
  global ballX
  global ballY
  global dX
  global dY
  if ballX>100 or ballX<-100:
    dX = -dX
  if ballY>100 or ballY<-100:
    dY = -dY
  ballX+=dX
  ballY+=dY
  ball.goto(ballX,ballY)
  screen.ontimer(animate,5)
  
setupBall()
screen.ontimer(animate,5)

result
console