Advertisement
here2share

# Tk_particles.py

Sep 6th, 2016
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.05 KB | None | 0 0
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3.  
  4. # Tk_particles.py
  5.  
  6. import Tkinter,time,random
  7. from math import*
  8. root=Tkinter.Tk(className='Particles')
  9. cv=Tkinter.Canvas(root,width=640,height=480,bg='black')
  10. x,y=int(cv['width'])/2,int(cv['height'])/2
  11. running=1
  12. star_color=['#fcffc8','#d0f4ff','#d8ffd0','#fad8fe']
  13. star_width=1
  14. s_d=[[x,y,random.randrange(i*5,i*5+5),random.uniform(3,6),random.choice(star_color),star_width] for i in range(72)]
  15. star=[cv.create_oval(s_d[i][0]-s_d[i][5]/2.0,s_d[i][1]-s_d[i][5]/2.0,
  16.                      s_d[i][0]+s_d[i][5]/2.0,s_d[i][1]+s_d[i][5]/2.0,
  17.                      fill=s_d[i][4],outline=s_d[i][4])
  18.                      for i in range(len(s_d))]
  19. s_type=5
  20. def quit(event):
  21.     global running
  22.     running=0
  23.     root.destroy()
  24. root.bind('<Button-2>',quit)
  25. def new_pos(event):
  26.     global x,y,reloc
  27.     x,y=event.x,event.y
  28.     reloc=100
  29. root.bind('<Button-1>',new_pos)
  30. def new_type(event):
  31.     global s_type,reloc
  32.     s_type+=1
  33.     if s_type==len(type_):
  34.         s_type=0
  35.     reloc=100
  36. root.bind('<Button-3>',new_type)
  37. def move_type(i,s_type):
  38.     global type_
  39.     type_=[[s_d[i][3]*cos(s_d[i][2]),s_d[i][3]*sin(s_d[i][2])],
  40.            [s_d[i][3]*cos(s_d[i][2]),s_d[i][3]*cos(s_d[i][2])],
  41.            [-s_d[i][3]*sin(s_d[i][2]),s_d[i][3]*sin(s_d[i][2])],
  42.            [s_d[i][3]*tan(s_d[i][2]),s_d[i][3]*sin(s_d[i][2])],
  43.            [s_d[i][3]*sin(s_d[i][2]),s_d[i][3]*tanh(s_d[i][2])],
  44.            [s_d[i][3]*tanh(s_d[i][2]),s_d[i][3]*tan(s_d[i][2])]]
  45.     cv.move(star[i],type_[s_type][0],type_[s_type][1])
  46.  
  47. def star_sky():
  48.     for i in range(len(star)):
  49.         move_type(i,s_type)
  50.         if cv.bbox(star[i])[0]>int(cv['width']) or cv.bbox(star[i])[1]>int(cv['height']) or cv.bbox(star[i])[2]<0 or cv.bbox(star[i])[3]<0:
  51.             cv.delete(star[i])
  52.             s_d[i]=[x,y,random.randrange(i*10,i*10+10),random.uniform(3,6),random.choice(star_color),star_width]
  53.             star[i]=cv.create_oval(s_d[i][0]-s_d[i][5]/2.0,s_d[i][1]-s_d[i][5]/2.0,s_d[i][0]+s_d[i][5]/2.0,s_d[i][1]+s_d[i][5]/2.0,fill=s_d[i][4],outline=s_d[i][4])
  54.  
  55. delay=reloc=100
  56. while running:
  57.     if reloc < 1:
  58.         reloc=delay
  59.         new_type(())
  60.     reloc -= 1
  61.     cv.pack()
  62.     star_sky()
  63.     time.sleep(0.01)
  64.     cv.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement