Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_radial_coverage2.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 = 1600
- vectors = 1000
- midx,midy = 600,300
- TWO_PI = math.pi*2
- def radial_ref(angles=360): # 2500
- d = {}
- d2bn = 0
- if angles:
- d2bn = 360.0/angles
- for angle in range(angles):
- a = angle
- a = a*d2bn
- 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=0)
- timer = 0
- p = p2 = 0
- while 1:
- vectors = int(slist[0].get())+1000
- 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(0,midy,x,midy+y,fill='blue')
- canvas.create_line(WW,midy,WW+x,midy+y,fill='blue')
- canvas.create_line(midx,WW,midx+x,WW+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()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement