Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_symwave_loop.py
- from Tkinter import *
- import random
- import math
- import time
- WW = 680
- HH = 680
- root = Tk()
- root.geometry(str(WW)+"x"+str(HH)+"+5+5")
- canvas = Canvas(root, width=WW, height=HH)
- canvas.pack()
- radius = 100
- vectors = 2000
- midx,midy = WW/2,HH/2+20
- TWO_PI = math.pi*2
- def radial_ref(angles=360): # 2500
- d = {}
- d2bn = 0
- if angles:
- d2bn = 360.0/angles
- for angle in range(int(angles)):
- a = angle
- a = a*d2bn
- x = math.sin(math.radians(a))
- y = math.cos(math.radians(a))
- d[angle] = x,y
- return d
- class Slider:
- def __init__(self, master=None, label='', value=0.0, min=0.0, max=100):
- slist.append(0)
- slist[-1] = DoubleVar()
- s = Scale( master,
- label=label,
- variable=slist[-1],
- from_=min*1.0,
- to=max*1.0,
- orient=HORIZONTAL,
- length=max)
- slist[-1].set(value)
- s.place(x=(len(slist)-1)*120,y=0)
- slist = []
- Slider(canvas, label='sides', max=100, min=3)
- timer = 0
- p2 = 0
- while 1:
- sides = int(slist[0].get())
- if p2 != sides and timer < time.time():
- PERIM = radial_ref(vectors)
- t = radial_ref(vectors/sides)
- fix = (int(vectors/sides)*sides)/(1.0*vectors)
- WAVE = [t[z][1] for z in range(len(t))]
- L_Wave = len(WAVE)
- canvas.delete('all')
- points = []
- for i in range(vectors):
- r = 250-WAVE[int(i*fix)%L_Wave]*20
- x,y = PERIM[i]
- x = x*r
- y = y*r
- points += [midx+x,midy+y]
- canvas.create_line(points+[points[:2]],fill='blue')
- canvas.create_rectangle(midx-70,midy-20,midx+70,midy+20,outline='yellow',fill='yellow')
- canvas.create_text(midx,midy,text=sides,font='arial 30',fill='blue')
- p2 = sides
- canvas.update()
Add Comment
Please, Sign In to add comment