Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_ani_ribbons.py
- from math import cos,sin,pi,radians
- import time
- import random
- r=random.randint
- now=time.time
- try:
- import tkinter as tk
- except:
- import Tkinter as tk
- root=tk.Tk()
- root.title("Tk Animating Ribbons")
- go=0
- ww=640
- hh=640
- canvas=tk.Canvas(root,width=ww,height=hh)
- canvas.pack(fill="both",expand=True)
- do360={}
- for angle in range(0,360):
- a=cos(radians(angle))
- b=sin(radians(angle))
- do360[angle]=(a,b)
- def i360(angle):
- return do360[angle%360]
- # for fluidity
- wave={}
- sp={}
- def WAVE(span):
- global polar
- polar *= -1
- incr=360.0/span
- for angle in range(0,span):
- i=cos(radians((angle*incr)*polar))
- yield i
- colors='darkorange blue'.split()
- marks={}
- def make_line(i,z):
- x0,y0,x1,y1=(i360(z)+i360(z))
- x0*=r0
- y0*=r0
- x1*=r1
- y1*=r1
- t=x+xm+x0,y+ym+y0,x+xm+x0+x1,y+ym+y0+y1
- if go:
- t=canvas.create_line(t,width=2,fill=colors[i])
- marks[i].append(t)
- xm,ym=ww/2,hh/2
- L=800
- for i in (0,1):
- x=y=0
- marks[i]=[]
- r0=100
- r1=300
- marks[i,'z']=r(0,359)
- for z in range(0,L,4):
- make_line(i,z)
- def get_wave(span):
- global wave
- while 1:
- try:
- zzz=next(wave)*span/5.0
- break
- except:
- wave=WAVE(span)
- return zzz
- go=1
- polar = -1
- rnd_rotate = 180
- while go:
- time=now()+0.05
- for i in [0]:
- canvas.delete(marks[i][0])
- marks[i] = marks[i][-L:]
- z=marks[i,'z']
- x=get_wave(600)
- y=get_wave(500)
- r0=get_wave(300)+100
- r1=get_wave(200)+300
- z += 1
- z %= 360
- marks[i,'z']=z
- if z == rnd_rotate:
- polar = random.choice((1,-1))
- rnd_rotate = (r(20,340)+z)%360
- canvas.update()
- make_line(i,z)
- while time > now():
- 0
- tk.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement