Created
August 27, 2011 02:47
-
-
Save basicxman/1174894 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from Tkinter import * | |
| import random | |
| def animation_threshold(): | |
| global i | |
| if i == 50000: | |
| i = 0 | |
| return False | |
| else: | |
| i += 1 | |
| return True | |
| def change_dir(item): | |
| global objects | |
| objects[item][0] *= -1 | |
| cv.move(objects[item][1], objects[item][0], 0) | |
| cv.update() | |
| def update_objects(): | |
| global objects | |
| for i in range(0, len(objects)): | |
| x = cv.coords(objects[i][1])[0] | |
| if x < 5: | |
| change_dir(i) | |
| elif x > 470: | |
| change_dir(i) | |
| else: | |
| cv.move(objects[i][1], objects[i][0], 0) | |
| cv.update() | |
| def add_object(event = None): | |
| global objects | |
| x, y = random.randint(0, 475), random.randint(25, 475) | |
| objects.append([5, cv.create_oval(x, y, x + 25, y + 25, fill = "blue")]) | |
| cv.update() | |
| root = Tk() | |
| w = 500 | |
| h = 500 | |
| cv = Canvas(width = w, height = h) | |
| cv.pack() | |
| cv.update() | |
| objects = [] | |
| i = 0 | |
| root.bind("a", add_object) | |
| add_object() | |
| while True: | |
| if animation_threshold(): continue | |
| update_objects() | |
| root.mainloop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment