Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_0-3-4-7_animation.py
- import math
- from time import time
- from tkinter import *
- ww=hh=500
- ctr=ww/2
- t=1.0/2
- d_fade=[round(i*0.01,2) for i in range(1000)]
- z=[0.0 for i in range(200)]
- z += [round(t*i*0.01,3) for i in range(200)]
- z += [1.0 for i in range(400)]
- z += [round(t*i*0.01,3) for i in range(200,0,-1)]
- d_fade=dict(zip(d_fade,z))
- d_fade[10.0] = 0.0
- L_fade=len(d_fade)
- root=Tk()
- root.title("# 0-3-4-7 Animation")
- root.geometry("%dx%d+0+0"%(ww,hh))
- root2=Tk()
- root2.geometry("%dx%d+0+0"%(ww,hh))
- canvas=Canvas(root, width=ww, height=hh)
- canvas.pack()
- cv2=Canvas(root2, width=ww, height=hh)
- cv2.pack()
- root.overrideredirect(True)
- root.resizable(False, False)
- root.update_idletasks()
- root.wm_attributes("-topmost", True)
- root2.overrideredirect(True)
- root2.resizable(False, False)
- root2.update_idletasks()
- root2.wm_attributes("-topmost", True)
- omega=1.0 # kiloradians per second
- ratio=0.8
- m=7
- n=3
- side=min(ww, hh)
- theta=omega*time()
- phi=theta*(1.0-m/n)
- cx,cy=ww/2,hh/2
- r0=0.4*side
- r1=r0*n/m
- # 7-pointed star
- steps=200
- star7pt=[]
- for k in range(-10,steps):
- theta=k*n*2.0*math.pi/steps
- phi=theta*(1.0-m/n)
- x,y=(cx+(r0-r1)*math.cos(theta), cy+(r0-r1)*math.sin(theta))
- x,y=(x+ratio*r1*math.cos(phi), y+ratio*r1*math.sin(phi))
- star7pt += [(x,y)]
- def dot(x, y):
- cv2.create_oval(x+rdot, y+rdot, x-rdot, y-rdot, fill=color, outline='')
- canvas.create_oval(x+rdot, y+rdot, x-rdot, y-rdot, fill=color, outline='')
- def polygon(obj):
- cv2.create_line(obj, fill=color, width=5)
- def txt(x, y):
- cv2.create_text(x, y, text=c, font=('verdana','30'), fill='blue')
- canvas.create_text(x, y, text=c, font=('verdana','30'), fill='blue')
- def fade():
- root2.wm_attributes('-alpha', alpha) # 0.0 to 1.0
- def quit(e=None):
- root2.destroy()
- root.destroy()
- btnA = Button(cv2, text="CLOSE", font=("Ariel, 10"), command=quit)
- btnB = Button(canvas, text="CLOSE", font=("Ariel, 10"), command=quit)
- btnA.place(x=ww-100,y=hh-50)
- btnB.place(x=ww-100,y=hh-50)
- zzz=time()
- while 1:
- xy=[]
- circles=[]
- triangles=[]
- ttt=time()-zzz
- show=ttt%70
- t=round((ttt)%10,2)
- alpha=d_fade[t]
- for i in range(m-n):
- theta=omega*ttt+2.0*math.pi*i/(m-n)
- px,py=(cx+(r0-r1)*math.cos(theta), cy+(r0-r1)*math.sin(theta))
- triangle=[]
- for j in range(n):
- phi=(theta-2.0*math.pi*i/(m-n))*(1.0-m/n)
- psi=phi+2.0*math.pi*j/n
- qx,qy=(px+ratio*r1*math.cos(psi), py+ratio*r1*math.sin(psi))
- xy += [(qx,qy)]
- triangle += [(qx,qy)]
- triangles += [triangle]
- phi=(theta-2.0*math.pi*i/(m-n))*(1.0-m/n)
- qx,qy=px+math.cos(phi), py+math.sin(phi)
- circles += [(qx, qy)]
- # draw
- canvas.delete('all')
- cv2.delete('all')
- # 7-Pointed Star (always drawn first)
- color='grey90'
- cv2.create_line(star7pt, fill=color, width=5)
- canvas.create_line(star7pt, fill=color, width=5)
- # Circles
- if show > 60:
- color='lightgreen'
- for x,y in circles:
- rdot=70
- cv2.create_oval(x+rdot, y+rdot, x-rdot, y-rdot, fill=color, outline='')
- # Full Circle
- r=188
- cv2.create_oval(cx+r, cy+r, cx-r, cy-r, fill='', outline='cyan', width=5)
- # 2 Prisms
- elif show > 50:
- color='pink'
- polygon([xy[i-1] for i in (1,2,5,4,1,3,6,4)])
- polygon([xy[i-1] for i in (7,8,11,10,7,9,12,10)])
- polygon([xy[i-1] for i in (8,9,12,11)])
- polygon([xy[i-1] for i in (2,3,6,5)])
- # Hyper Spiral 2
- elif show > 40:
- color='green'
- polygon([xy[i-1] for i in (1,5,7,10,2,6,8,11,3,4,9,12,1)])
- # Hyper Spiral
- elif show > 30:
- color='purple'
- polygon([xy[i-1] for i in (1,5,9,10,2,6,7,11,3,4,8,12,1)])
- # Bouncy Squares
- elif show > 20:
- color='lightgreen'
- polygon([xy[i-1] for i in (1,5,9,12,1)])
- color='lightblue'
- polygon([xy[i-1] for i in (2,6,7,10,2)])
- color='pink'
- polygon([xy[i-1] for i in (3,4,8,11,3)])
- # Squares
- elif show > 10:
- color='lightblue'
- for i in range(3):
- polygon([xy[i+j] for j in range(0,12,3)]+[xy[i]])
- # Triangles
- else:
- color='lightgreen'
- for triangle in triangles:
- polygon(triangle+[triangle[0]])
- # Dots (always drawn last)
- c=1
- for x,y in xy:
- color='orange'
- rdot=7
- dot(x,y)
- # txt(x,y)
- c += 1
- fade()
- canvas.update()
- cv2.update()
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement