here2share

# Tk_symwave_loop.py

Nov 1st, 2020 (edited)
1,229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.64 KB | None | 0 0
  1. # Tk_symwave_loop.py
  2.  
  3. from Tkinter import *
  4. import random
  5. import math
  6. import time
  7.  
  8. WW = 680
  9. HH = 680
  10. root = Tk()
  11. root.geometry(str(WW)+"x"+str(HH)+"+5+5")
  12. canvas = Canvas(root, width=WW, height=HH)
  13. canvas.pack()
  14.  
  15. radius = 100
  16. vectors = 2000
  17. midx,midy = WW/2,HH/2+20
  18. TWO_PI = math.pi*2
  19.  
  20. def radial_ref(angles=360): # 2500
  21.     d = {}
  22.     d2bn = 0
  23.     if angles:
  24.         d2bn = 360.0/angles
  25.     for angle in range(int(angles)):           
  26.         a = angle
  27.         a = a*d2bn
  28.         x = math.sin(math.radians(a))
  29.         y = math.cos(math.radians(a))
  30.         d[angle] = x,y
  31.     return d
  32.  
  33. class Slider:
  34.     def __init__(self, master=None, label='', value=0.0, min=0.0, max=100):
  35.         slist.append(0)
  36.         slist[-1] = DoubleVar()
  37.         s = Scale(  master,
  38.                     label=label,
  39.                     variable=slist[-1],
  40.                     from_=min*1.0,
  41.                     to=max*1.0,
  42.                     orient=HORIZONTAL,
  43.                     length=max)
  44.         slist[-1].set(value)
  45.         s.place(x=(len(slist)-1)*120,y=0)
  46.    
  47. slist = []
  48. Slider(canvas, label='sides', max=100, min=3)
  49.  
  50. timer = 0
  51. p2 = 0
  52. while 1:
  53.     sides = int(slist[0].get())
  54.     if p2 != sides and timer < time.time():
  55.         PERIM = radial_ref(vectors)
  56.         t = radial_ref(vectors/sides)
  57.         fix = (int(vectors/sides)*sides)/(1.0*vectors)
  58.         WAVE = [t[z][1] for z in range(len(t))]
  59.         L_Wave = len(WAVE)
  60.         canvas.delete('all')
  61.         points = []
  62.         for i in range(vectors):
  63.             r = 250-WAVE[int(i*fix)%L_Wave]*20
  64.             x,y = PERIM[i]
  65.             x = x*r
  66.             y = y*r
  67.             points += [midx+x,midy+y]
  68.         canvas.create_line(points+[points[:2]],fill='blue')
  69.         canvas.create_rectangle(midx-70,midy-20,midx+70,midy+20,outline='yellow',fill='yellow')
  70.         canvas.create_text(midx,midy,text=sides,font='arial 30',fill='blue')
  71.         p2 = sides
  72.     canvas.update()
Add Comment
Please, Sign In to add comment