Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. from tkinter import *
  2. import random
  3. import time
  4.  
  5. root = Tk()
  6. root.geometry("1300x800")
  7.  
  8. can = Canvas(root, width=1300, height=800, bg="white")
  9. can.pack()
  10.  
  11.  
  12. colors = ["red","yellow","black","blue","green","brown"]
  13.  
  14. class sneg(object):
  15. def __init__(self, color):
  16. self.x = random.randint(100, 1200)
  17. self.y = random.randint(100, 700)
  18. self.R = random.randint(10, 50)
  19. self.oval = can.create_oval(self.x-self.R,self.y-self.R,self.x+self.R,self.y+self.R,fill=color)
  20. self.dx = random.randint(-8, 8)
  21. self.dy = random.randint(-8, 8)
  22. def step(self):
  23. self.x = self.x + self.dx
  24. self.y = self.y + self.dy
  25. can.move(self.oval, self.dx, self.dy)
  26. def check(self):
  27. if self.x > 1250 or self.x < 50:
  28. self.dx = -(self.dx)
  29. if self.y > 750 or self.y < 50:
  30. self.dy = -(self.dy)
  31. def go(self):
  32. self.step()
  33. self.check()
  34. can.update()
  35.  
  36. snegopad = []
  37. for i in range(0,100):
  38. snegopad.append(sneg(colors[random.randint(1, 5)]))
  39. while True:
  40. for i in range(0,100):
  41. snegopad[i].go()
  42. #time.sleep(0.001)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement