Advertisement
here2share

# Tk_square_unicorn.py

Oct 4th, 2019
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.11 KB | None | 0 0
  1. # Tk_square_unicorn.py
  2.  
  3. from Tkinter import *
  4. from PIL import Image, ImageTk
  5. from math import *
  6. import random
  7. import re
  8.  
  9. root = Tk()
  10. root.title("Tk Square Unicorn")
  11. root.geometry("500x500")
  12. wi = 500
  13. he = 500
  14. w = Canvas(root, width=wi, height=he)
  15. w.pack()
  16.  
  17. img = Image.new( 'RGB', (wi,he))
  18.  
  19. rainbow=[]
  20. def z(r,g,b):
  21.     rainbow.append((r,g,b))
  22. r,g,b=255,0,0
  23. for g in range(256):
  24.     z(r,g,b)
  25. for r in range(254, -1, -1):
  26.     z(r,g,b)
  27. for b in range(256):
  28.     z(r,g,b)
  29. for g in range(254, -1, -1):
  30.     z(r,g,b)
  31. for r in range(256):
  32.     z(r,g,b)
  33. for b in range(254, -1, -1):
  34.     z(r,g,b)
  35. 0
  36.  
  37. mid = 250
  38. bow = len(rainbow)
  39. def d(x,y):
  40.     z = int(degrees(atan2(mid-x,mid-y)*100/22))
  41.     return z
  42. 0
  43.  
  44. zzz = []
  45. for y in range(he):
  46.     for x in range(wi):
  47.         zzz.append(d(x,y))
  48. 0
  49. zzz = list(set(zzz))
  50. zzz.sort()
  51.  
  52. px2rgb = dict(zip(zzz,rainbow))
  53.  
  54. def run():
  55.     p = '#000000'
  56.     for y in range(he):
  57.         for x in range(wi):
  58.             z = d(x,y)
  59.             try:
  60.                 z = px2rgb[z]
  61.                 c = '#%02x%02x%02x' % tuple(z)
  62.             except:
  63.                 c = p
  64.             w.create_line((x, y, x+1,y+2),fill=c)
  65.             p = c
  66.         root.update()
  67. 0
  68. run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement