Advertisement
here2share

# Tk_spiral_gen.py

Jan 25th, 2019
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.74 KB | None | 0 0
  1. # Tk_spiral_gen.py
  2.  
  3. from Tkinter import *
  4. import math
  5.  
  6. def spiral_gen(radius, step, resolution=.1, start=0.0, angle=0.0):
  7.     dist = start+0.0
  8.     coords=[]
  9.     while dist*math.hypot(math.cos(angle),math.sin(angle))<radius:
  10.         x = int(dist*math.cos(angle))
  11.         y = int(dist*math.sin(angle))
  12.         if [x,y] not in coords:
  13.             coords.append([x,y])
  14.         dist+=step
  15.         angle+=resolution
  16.     return coords
  17. root = Tk()
  18. root.title("Spiral Generator")
  19.  
  20. c_width = 600
  21. c_height = 600
  22. canvas = Canvas(root, width=c_width, height=c_height, bg='white')
  23. canvas.pack()
  24.  
  25. spiral = spiral_gen(250, 0.02, 0.005, 20)
  26.  
  27. for x,y in spiral:
  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.  
  33. print(spiral)
  34. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement