Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_basic_vectoring.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 = 300
- vectors = 1000
- midx,midy = 600,360
- 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.sin(math.radians(a))
- y = math.cos(math.radians(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.append(0)
- 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=(len(slist)-1)*120,y=0)
- slist = []
- Slider(canvas, label='vector points', max=100, min=3)
- Slider(canvas, label='radius', max=1000, min=10)
- timer = 0
- p = p2 = 0
- while 1:
- vectors = int(slist[0].get())
- radius = int(slist[1].get())
- if p <> [vectors,radius]:
- timer = time.time()+0.3
- p = [vectors,radius]
- if p2 <> vectors and timer < time.time():
- PERIM = radial_ref(vectors)
- canvas.delete('all')
- points = []
- for i in range(vectors):
- x,y = PERIM[i]
- x *= radius
- y *= radius
- points += [WW-320+x,midy+y]
- canvas.create_line(points+[points[:2]],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,radius]
- canvas.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement