Python Script

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
“””
Created on Tue Mar 31 16:35:37 2020
@author: robtorres
“””

from tkinter import *
import time
import random

WIDTH = 800
HEIGHT = 500

tk = Tk()
canvas = Canvas(tk, width=WIDTH, height=HEIGHT, bg=”black”)
tk.title(“WackyCoder Bouncy Balls”)
canvas.pack()

#ListColor List
colors = [‘red’, ‘green’, ‘blue’, ‘orange’, ‘yellow’, ‘cyan’, ‘magenta’,
‘dodgerblue’, ‘turquoise’, ‘grey’, ‘gold’, ‘pink’]

 

#Class: Ball
class Ball:
def __init__(self):
self.size = random.randrange(100, 200)
color = random.choice(colors)
self.shape = canvas.create_oval(0, 0, self.size, self.size, fill=color)
self.speedx = random.randrange(1, 10)
self.speedy = random.randrange(1, 10)

def update(self):
canvas.move(self.shape, self.speedx, self.speedy)
pos = canvas.coords(self.shape)
if pos[2] >= WIDTH or pos[0] <= 0:
self.speedx *= -1
if pos[3] >= HEIGHT or pos[1] <= 0:
self.speedy *= -1

ball_list = []
for i in range(1):
ball_list.append(Ball())

while True:
for ball in ball_list:
ball.update()

tk.update()
time.sleep(0.01)