from tkinter import*
from CanvasBall import *
from time import *

class BallWorld (object):
    ballParams = [[100, 100, 18,  2, 4],
                  [ 50,  50, 25, 12, 4]]

    width = 500
    height = 400

    def __init__ (self):
        self.root = Tk ()
        self.canvas = Canvas (self.root,
                              bg = 'black',
                              width = self.width,
                              height = self.height)
        self.canvas.pack ()
        button = Button (self.root,
                         text = "start",
                         command = self.buttonPressed)
        button.pack ()
        self.balls = []
        for x, y, r, dx, dy in self.ballParams:
            self.balls.append (CanvasBall (self.canvas,
                                           x, y, dx, dy, r,
                                           self.width, self.height))

    def buttonPressed (self):
        while True:
            for ball in self.balls:
                ball.clear ()
            for ball in self.balls:
                ball.update ()
            for ball in self.balls:
                ball.draw ()
            self.canvas.update ()
            sleep (0.015)

    def mainloop (self):
        self.root.mainloop ()


world = BallWorld ()
world.mainloop ()
