Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import *
- import random
- import time
- root = Tk()
- root.geometry("1300x800")
- can = Canvas(root, width=1300, height=800, bg="white")
- can.pack()
- colors = ["red","yellow","black","blue","green","brown"]
- class sneg(object):
- def __init__(self, color):
- self.x = random.randint(100, 1200)
- self.y = random.randint(100, 700)
- self.R = random.randint(10, 50)
- self.oval = can.create_oval(self.x-self.R,self.y-self.R,self.x+self.R,self.y+self.R,fill=color)
- self.dx = random.randint(-8, 8)
- self.dy = random.randint(-8, 8)
- def step(self):
- self.x = self.x + self.dx
- self.y = self.y + self.dy
- can.move(self.oval, self.dx, self.dy)
- def check(self):
- if self.x > 1250 or self.x < 50:
- self.dx = -(self.dx)
- if self.y > 750 or self.y < 50:
- self.dy = -(self.dy)
- def go(self):
- self.step()
- self.check()
- can.update()
- snegopad = []
- for i in range(0,100):
- snegopad.append(sneg(colors[random.randint(1, 5)]))
- while True:
- for i in range(0,100):
- snegopad[i].go()
- #time.sleep(0.001)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement