Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_radial_coverage_test.py
- from Tkinter import *
- import random
- import math
- import time
- WW = 1200
- HH = 680
- root = Tk()
- root.geometry(str(WW)+"x"+str(HH)+"+5+5")
- canvas = Canvas(root, width=WW, height=HH)
- canvas.pack()
- r = WW+80
- midx,midy = 600,300
- TWO_PI = math.pi*2
- def radial_ref(angles=360): # 2500
- d = {}
- t = 1
- if angles:
- t = (math.pi*2)/angles
- for angle in range(angles):
- a = angle*t
- x = math.cos(a)
- y = math.sin(a)
- d[angle] = x,y
- print len(d)
- return d
- class Slider:
- def __init__(self, master=None, label='', value=0.0, min=0.0, max=100):
- 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=0,y=0)
- slist = []
- sliderLabels = ['vector points','','','']
- for i in range(1):
- slist.append(0)
- Slider(canvas, label=sliderLabels[i], max=WW-5, min=3)
- timer = 0
- p = p2 = 0
- while 1:
- vectors = int(slist[0].get())
- if p != vectors:
- timer = time.time()+0.3
- p = vectors
- if p2 != vectors and timer < time.time():
- PERIM = radial_ref(vectors)
- canvas.delete('all')
- for i in range(vectors):
- x,y = PERIM[i]
- x *= r
- y *= r
- canvas.create_line(midx,midy,midx+x,midy+y,fill='blue')
- canvas.create_rectangle(midx-70,midy-20,midx+70,midy+20,outline='yellow',fill='yellow')
- canvas.create_text(midx,midy,text=vectors,font='arial 30',fill='blue')
- p2 = vectors
- canvas.update()
Add Comment
Please, Sign In to add comment