-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathbouncingBallAnimation.py
More file actions
81 lines (57 loc) · 2.23 KB
/
bouncingBallAnimation.py
File metadata and controls
81 lines (57 loc) · 2.23 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/python
# bouncing ball animation in Python
import colorama, os, sys, time, traceback
from colorama import Fore, Style
from datetime import datetime
from tkinter import *
colorama.init()
def checkOs():
print("Started checking operating system at", datetime.now().strftime("%m-%d-%Y %I:%M %p"))
if sys.platform == "win32":
print(Fore.GREEN + "Operating System:", end=""); sys.stdout.flush()
os.system('ver')
print(Style.RESET_ALL, end="")
elif sys.platform == "darwin":
print(Fore.GREEN + "Operating System: ")
os.system('sw_vers')
print(Style.RESET_ALL, end="")
elif sys.platform == "linux":
print(Fore.GREEN + "Operating System: ")
os.system('uname -r')
print(Style.RESET_ALL, end="")
print("Finisehd checking operating system at", datetime.now().strftime("%m-%d-%Y %I:%M %p"))
print("")
def bouncingBall():
print("\nBouncing ball anmiation in Python.\n")
try:
checkOs()
gui = Tk()
gui.geometry("800x600")
gui.title("Pi Animation")
canvas = Canvas(gui,width=800,height=600,bg='white')
canvas.pack()
ball1 = canvas.create_oval(5,5,60,60, fill='red')
xa = 5
ya = 10
startDateTime = datetime.now()
print("Started bouncing ball animation at", startDateTime.strftime("%m-%d-%Y %I:%M %p"))
while True:
canvas.move(ball1,xa,ya)
pos=canvas.coords(ball1)
if pos[3] >= 600 or pos[1] <= 0:
ya = -ya
if pos[2] >= 800 or pos[0] <= 0:
xa = -xa
gui.update()
time.sleep(.025)
print(Fore.GREEN + "Successfully ran bouncing ball animation." + Style.RESET_ALL)
finishedDateTime = datetime.now()
print("Finished bouncing ball animation at", finishedDateTime.strftime("%m-%d-%Y %I:%M %p"))
duration = finishedDateTime - startDateTime
print("Total execution time: {0} second(s)".format(duration.seconds))
print("")
except Exception as e:
print(Fore.RED + "Failed to run bouncing ball animation.")
traceback.print_exc()
exit("" + Style.RESET_ALL)
bouncingBall()