Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_sparkler.py
- from Tkinter import *
- from random import randrange as rnd, random
- import time
- root = Tk()
- root.geometry('800x600')
- canv = Canvas(bg='#ADC5E3')
- canv.pack(fill=BOTH,expand=1)
- class Pixel():
- def __init__(self,x,y,dx,dy,r,dr):
- self.x = x
- self.y = y
- self.dx = dx
- self.dy = dy
- self.r = r
- self.dr = dr
- color = 'yellow'
- self.id = canv.create_oval(x-r,y-r,x+r,y+r,fill=color,outline='')
- def move(self):
- self.x += self.dx/2
- self.y += self.dy/2
- self.dx *= 0.99
- self.dy *= 0.99
- self.r -= self.dr
- if self.r > 0:
- canv.coords(self.id,self.x-self.r,self.y-self.r,self.x+self.r,self.y+self.r)
- root.after(20,self.move)
- else:
- canv.delete(self.id)
- if rnd(4) == 0:
- p = Pixel(self.x,self.y,rnd(-10,10),rnd(-10,10),random()*2,0.1+random())
- p.move()
- def newPixel():
- p = Pixel(mx,my,rnd(-10,10),rnd(-10,10),rnd(5,9),0.1+random())
- p.move()
- root.after(10,newPixel)
- def move(event):
- global mx,my
- mx,my = event.x,event.y
- count = 0
- mx = 400
- my = 300
- canv.bind('<Motion>',move)
- newPixel()
- mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement