Advertisement
here2share

# Tk_spiralgram.py

Feb 15th, 2021
1,035
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.07 KB | None | 0 0
  1. # Tk_spiralgram.py
  2.  
  3. from Tkinter import *
  4. import math
  5.  
  6. root = Tk()
  7.  
  8. ww = 520
  9. hh = 520
  10. r = (min(ww,hh)-5)/2
  11.  
  12. canvas = Canvas(root,width=ww,height=hh)
  13. canvas.pack()
  14.  
  15. rainbow = []
  16. def rgb():
  17.     rainbow.append('#{:02x}{:02x}{:02x}'.format(r,g,b))
  18.  
  19. r, g, b = 255, 0, 0
  20. for g in range(256):
  21.     rgb()
  22. for r in range(255, -1, -1):
  23.     rgb()
  24. for b in range(256):
  25.     rgb()
  26. for g in range(255, -1, -1):
  27.     rgb()
  28. for r in range(256):
  29.     rgb()
  30. for b in range(255, -1, -1):
  31.     rgb()
  32.  
  33. p = len(rainbow)/360.0
  34. r360 = [rainbow[int(z*p)] for z in range(360)]
  35.  
  36. points = []
  37. circ = int(math.pi * r**2) / 20
  38. p = 360.0/circ
  39. print circ
  40. for x in range(0,ww,2):
  41.     for y in range(x%2,hh,2):
  42.         canvas.create_rectangle((x,y,x+2,y+2),fill='gray',outline=None)
  43.  
  44. for t in range(circ):
  45.     t *= p
  46.     x = math.sin(t) + math.sin(6*t)/2 + math.cos(14*t)/3
  47.     y = math.cos(t) + math.cos(6*t)/2 + math.sin(14*t)/3
  48.     angle = math.degrees(math.atan2(x,y))
  49.     x,y = [z*140+r-5 for z in (x,y)]
  50.     color = r360[int(angle)]
  51.     canvas.create_oval((x,y,x+1,y+1),fill=color,outline=color)
  52.  
  53. canvas.update()
  54. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement