here2share

# Tk_radial_coverage_test.py

Oct 30th, 2020 (edited)
2,273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.50 KB | None | 0 0
  1. # Tk_radial_coverage_test.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 = WW+80
  16. midx,midy = 600,300
  17. TWO_PI = math.pi*2
  18.  
  19. def radial_ref(angles=360): # 2500
  20.     d = {}
  21.     t = 1
  22.     if angles:
  23.         t = (math.pi*2)/angles
  24.     for angle in range(angles):
  25.         a = angle*t
  26.         x = math.cos(a)
  27.         y = math.sin(a)
  28.         d[angle] = x,y
  29.     print len(d)
  30.     return d
  31.  
  32. class Slider:
  33.     def __init__(self, master=None, label='', value=0.0, min=0.0, max=100):
  34.         slist[-1] = DoubleVar()
  35.         s = Scale(  master,
  36.                     label=label,
  37.                     variable=slist[-1],
  38.                     from_=min*1.0,
  39.                     to=max*1.0,
  40.                     orient=HORIZONTAL,
  41.                     length=max)
  42.         slist[-1].set(value)
  43.         s.place(x=0,y=0)
  44.    
  45. slist = []
  46. sliderLabels = ['vector points','','','']
  47. for i in range(1):
  48.     slist.append(0)
  49.     Slider(canvas, label=sliderLabels[i], max=WW-5, min=3)
  50.  
  51. timer = 0
  52. p = p2 = 0
  53. while 1:
  54.     vectors = int(slist[0].get())
  55.     if p != vectors:
  56.         timer = time.time()+0.3
  57.         p = vectors
  58.     if p2 != vectors and timer < time.time():
  59.         PERIM = radial_ref(vectors)
  60.         canvas.delete('all')
  61.         for i in range(vectors):
  62.             x,y = PERIM[i]
  63.             x *= r
  64.             y *= r
  65.             canvas.create_line(midx,midy,midx+x,midy+y,fill='blue')
  66.             canvas.create_rectangle(midx-70,midy-20,midx+70,midy+20,outline='yellow',fill='yellow')
  67.             canvas.create_text(midx,midy,text=vectors,font='arial 30',fill='blue')
  68.         p2 = vectors
  69.     canvas.update()
  70.  
Add Comment
Please, Sign In to add comment