Advertisement
here2share

# Tk_spiral_gen_speedtest.py

Jan 25th, 2019
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.23 KB | None | 0 0
  1. # Tk_spiral_gen_speedtest.py
  2.  
  3. from Tkinter import *
  4. import math
  5. import time
  6.  
  7. radius = 250
  8. step = 0.02
  9. resolution = 0.005
  10. start = start2 = 20
  11.  
  12. angle = 0.0
  13. dist = start+0.0
  14.  
  15. c_width = 600
  16. c_height = 600
  17.  
  18. root = Tk()
  19. root.title("Spiral Generator")
  20.  
  21. canvas = Canvas(root, width=c_width, height=c_height, bg='white')
  22. canvas.pack()
  23.  
  24. go = time.time()
  25. while dist*math.hypot(math.cos(angle),math.sin(angle))<radius:
  26.     x = int(dist*math.cos(angle))
  27.     y = int(dist*math.sin(angle))
  28.     x += c_width/2
  29.     y += c_height/2
  30.     canvas.create_oval(x, y, x+1, y+1, fill="red")
  31.     canvas.update()
  32.     dist+=step
  33.     angle+=resolution
  34. print(time.time()-go,'secs')
  35.  
  36. def spiral_gen(radius, step, resolution=.1, start=0.0, angle=0.0):
  37.     dist = start+0.0
  38.     coords=[]
  39.     while dist*math.hypot(math.cos(angle),math.sin(angle))<radius:
  40.         x = int(dist*math.cos(angle))
  41.         y = int(dist*math.sin(angle))
  42.         if [x,y] not in coords:
  43.             coords.append([x,y])
  44.         dist+=step
  45.         angle+=resolution
  46.     return coords
  47.  
  48. spiral = spiral_gen(radius, step, resolution, start2)
  49.  
  50. canvas.delete('all')
  51. go = time.time()
  52. for x,y in spiral:
  53.     x += c_width/2
  54.     y += c_height/2
  55.     canvas.create_oval(x, y, x+1, y+1, fill="red")
  56.     canvas.update()
  57. print(time.time()-go,'secs')
  58.  
  59. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement