here2share

# Tk_radial_coverage2.py

Oct 30th, 2020
908
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Tk_radial_coverage2.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. r = 1600
  16. vectors = 1000
  17. midx,midy = 600,300
  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.cos(a)
  29.         y = math.sin(a)
  30.         d[angle] = x,y
  31.     print len(d)
  32.     return d
  33.  
  34. class Slider:
  35.     def __init__(self, master=None, label='', value=0.0, min=0.0, max=100):
  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=0,y=0)
  46.    
  47. slist = []
  48. sliderLabels = ['vector points','','','']
  49. for i in range(1):
  50.     slist.append(0)
  51.     Slider(canvas, label=sliderLabels[i], max=WW-5, min=0)
  52.  
  53. timer = 0
  54. p = p2 = 0
  55. while 1:
  56.     vectors = int(slist[0].get())+1000
  57.     if p <> vectors:
  58.         timer = time.time()+0.3
  59.         p = vectors
  60.     if p2 <> vectors and timer < time.time():
  61.         PERIM = radial_ref(vectors)
  62.         canvas.delete('all')
  63.         for i in range(vectors):
  64.             x,y = PERIM[i]
  65.             x *= r
  66.             y *= r
  67.             canvas.create_line(0,midy,x,midy+y,fill='blue')
  68.             canvas.create_line(WW,midy,WW+x,midy+y,fill='blue')
  69.             canvas.create_line(midx,WW,midx+x,WW+y,fill='blue')
  70.             canvas.create_rectangle(midx-70,midy-20,midx+70,midy+20,outline='yellow',fill='yellow')
  71.             canvas.create_text(midx,midy,text=vectors,font='arial 30',fill='blue')
  72.         p2 = vectors
  73.     canvas.update()
  74.  
RAW Paste Data