Advertisement
here2share

# Tk_radial_rainbow_2.py

Feb 25th, 2022
1,188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.02 KB | None | 0 0
  1. # Tk_radial_rainbow_2.py
  2.  
  3. from Tkinter import *
  4. from math import sqrt, atan2
  5. from random import shuffle as rs
  6.  
  7. def oRGB(rgb): # pass
  8.     r,g,b = rgb
  9.     return "#%02x%02x%02x" % (r,g,b)
  10.  
  11. ww = 600
  12. hh = 600
  13. root = Tk()
  14. root.title("# Tk_radial_rainbow 2")
  15. root.geometry("%dx%d+0+0"%(ww,hh))
  16. canvas = Canvas(root, width=ww, height=hh)
  17. canvas.grid()
  18.  
  19. stepSize = 5
  20. cols = ww / stepSize
  21. rows = hh / stepSize
  22. x = x0 = ww / 2
  23. y = y0 = hh / 2
  24.  
  25. xy = []
  26. for y in range(0,hh,stepSize):
  27.     for x in range(0,ww,stepSize):
  28.         distance = sqrt((x0-x)**2+(y0-y)**2)
  29.         xy2 = atan2(x-x0,y-y0)
  30.         xy.append(((int(distance), xy2),x,y))
  31.        
  32. xy.sort()
  33.  
  34. xy = [(x,y) for z,x,y in xy]
  35.  
  36. iii = 1
  37. COLORS = 'red orange yellow green blue purple'.split()
  38. t = stepSize
  39. i = 100
  40. s = ''
  41. while 1:
  42.     Lc = len(COLORS)
  43.     canvas.delete('all')
  44.     for x,y in xy:
  45.         if len(s) < 10:
  46.             s += str(i)
  47.             i += 1
  48.         iii = int(s[:3])
  49.         s = s[3:]
  50.         color = int(iii)%Lc
  51.         canvas.create_rectangle((x,y,x+t,y+t), fill=COLORS[color], outline='')
  52.     canvas.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement