Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_spiral_gen_speedtest.py
- from Tkinter import *
- import math
- import time
- radius = 250
- step = 0.02
- resolution = 0.005
- start = start2 = 20
- angle = 0.0
- dist = start+0.0
- c_width = 600
- c_height = 600
- root = Tk()
- root.title("Spiral Generator")
- canvas = Canvas(root, width=c_width, height=c_height, bg='white')
- canvas.pack()
- go = time.time()
- while dist*math.hypot(math.cos(angle),math.sin(angle))<radius:
- x = int(dist*math.cos(angle))
- y = int(dist*math.sin(angle))
- x += c_width/2
- y += c_height/2
- canvas.create_oval(x, y, x+1, y+1, fill="red")
- canvas.update()
- dist+=step
- angle+=resolution
- print(time.time()-go,'secs')
- def spiral_gen(radius, step, resolution=.1, start=0.0, angle=0.0):
- dist = start+0.0
- coords=[]
- while dist*math.hypot(math.cos(angle),math.sin(angle))<radius:
- x = int(dist*math.cos(angle))
- y = int(dist*math.sin(angle))
- if [x,y] not in coords:
- coords.append([x,y])
- dist+=step
- angle+=resolution
- return coords
- spiral = spiral_gen(radius, step, resolution, start2)
- canvas.delete('all')
- go = time.time()
- for x,y in spiral:
- x += c_width/2
- y += c_height/2
- canvas.create_oval(x, y, x+1, y+1, fill="red")
- canvas.update()
- print(time.time()-go,'secs')
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement