here2share

# Tk_radial_coverage.py

Oct 31st, 2020
1,208
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Tk_radial_coverage.py
  2.  
  3. from Tkinter import *
  4. import random
  5. import math
  6. import time
  7.  
  8. WW = 1200
  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 = 2000
  16. vectors = 1000
  17. midx,midy = 600,360
  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(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='vector points', max=1180, min=300)
  49.  
  50. timer = 0
  51. p = p2 = 0
  52. while 1:
  53.     vectors = int(slist[0].get())
  54.     if p <> vectors:
  55.         timer = time.time()+0.3
  56.         p = vectors
  57.     if p2 <> vectors and timer < time.time():
  58.         PERIM = radial_ref(vectors)
  59.         canvas.delete('all')
  60.         points = []
  61.         for i in range(vectors):
  62.             x,y = PERIM[i]
  63.             x *= radius
  64.             y *= radius
  65.             points += [WW-320+x,midy+y]
  66.             canvas.create_line(midx,midy,midx+x,midy+y,fill='blue')
  67.         canvas.create_rectangle(midx-70,midy-20,midx+70,midy+20,outline='yellow',fill='yellow')
  68.         canvas.create_text(midx,midy,text=vectors,font='arial 30',fill='blue')
  69.         p2 = vectors
  70.     canvas.update()
  71.  
RAW Paste Data