from Tkinter import *
import random
import time

window_width=800    #How many pixels tall
window_height=600   #How many pixels wide
class Ball:
    def __init__(self, canvas, color):
        self.canvas = canvas
        self.id = canvas.create_oval(10, 10, 25, 25, fill=color)
        self.canvas.move(self.id, 245, 100)
        self.x = 0
        self.y = -1
        self.old_x=0
        self.old_y=0
        self.canvas_height = self.canvas.winfo_height()

    def locate(self,new_x,new_y,show_path=False):
        self.canvas.coords(self.id, new_x, window_height-new_y, new_x+10, window_height-new_y-10)
        if show_path:
          canvas.create_line(self.old_x, window_height-self.old_y, new_x, window_height-new_y)
        self.old_x=new_x
        self.old_y=new_y

tk = Tk()
tk.title("Game")
tk.resizable(0, 0)
tk.wm_attributes("-topmost", 1)
canvas = Canvas(tk, width=window_width, height=window_height, bd=0, highlightthickness=0)
canvas.pack()
tk.update()
ball = Ball(canvas, 'red')
x = 10
y = window_height-50
v_y = -2.0 #pixels/loop_time   #Y component of the ball's velocity in computer units
keep_looping = True
while keep_looping:
    ball.locate(x,y,show_path=False)     #Moves to ball to location (x,y)
    tk.update_idletasks()    #This line and the next force a refresh of the window
    tk.update()
    time.sleep(0.01) # This is the loop time in seconds.  Make it bigger to slow down the action
    y = y + v_y      # Technically, this should be y = y + v_y*_delta_t, but 
                     # delta_t = 1.0 loop times, so multiplying by 1.0 can be left out.
    if y <= 0:
      print("We have hit the bottom")
      canvas.create_text(window_width / 2,
              window_height / 2,
              text="WE HAVE HIT THE BOTTOM.",fill="red")
      keep_looping = False

a=raw_input("Press Enter key to continue")    
    