Advertisement
here2share

# Tk_rainbow_island_gen.py

Oct 15th, 2019
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.50 KB | None | 0 0
  1. # Tk_rainbow_island_gen.py -- slow
  2.  
  3. from Tkinter import *
  4. from PIL import Image, ImageTk
  5. from math import *
  6. import random
  7. import re
  8. import time
  9.  
  10. w = h = 200
  11. vxy = (1533.0)/(w*h)
  12. print vxy
  13.  
  14. rainbow=[]
  15. def z(r,g,b):
  16.     rainbow.append((r,g,b))
  17. r,g,b=255,0,0
  18. for g in range(256):
  19.     z(r,g,b)
  20. for r in range(254, -1, -1):
  21.     z(r,g,b)
  22. for b in range(256):
  23.     z(r,g,b)
  24. for g in range(254, -1, -1):
  25.     z(r,g,b)
  26. for r in range(256):
  27.     z(r,g,b)
  28. for b in range(254, -1, -1):
  29.     z(r,g,b)
  30. 0
  31.  
  32. z = rainbow.index((0,255,0))
  33. rainbow = rainbow[z:] + rainbow[:z]
  34.  
  35. xy = []
  36. for y in range(0,h):
  37.     for x in range(0,w):
  38.         xy.append([x,y])
  39. random.shuffle(xy)
  40.  
  41. def mv():
  42.     if zzz:
  43.         x,y = zzz[0]
  44.         canvas.create_line((x,y,x+1,y+1),fill='#%02x%02x%02x' % rainbow[int(len(xy)*vxy)])
  45.         climb = [   [x-1,y-1],[x+1,y+1],[x-1,y+1],[x+1,y-1],[x-1,y],[x,y-1],[x+1,y],[x,y+1],
  46.                     [x-2,y-2],[x+2,y+2],[x-2,y+2],[x+2,y-2],[x-2,y],[x,y-2],[x+2,y],[x,y+2]]
  47.         random.shuffle(climb)
  48.         climb = climb[:6]
  49.         for z in climb:
  50.             try:
  51.                 zzz.append(xy.pop(xy.index(z)))
  52.                 x,y = z
  53.                 canvas.create_line((x,y,x+1,y+1), fill='#%02x%02x%02x' % rainbow[int(len(xy)*vxy)])
  54.             except:
  55.                 0
  56. 0
  57.  
  58. root = Tk()
  59. root.title("Tk Rainbow Island Gen")
  60. canvas = Canvas(root, width=w, height=h)
  61. canvas.pack()
  62.  
  63. peaks = 6
  64. zzz,xy = xy[:peaks],xy[peaks:]
  65. t = 0
  66. while zzz:
  67.     zzz,z = zzz[:6],zzz[6:]
  68.     random.shuffle(zzz)
  69.     zzz = zzz+z
  70.     mv()
  71.     zzz.pop(0)
  72.     if t < time.time():
  73.         t = time.time()+10
  74.         print len(xy)
  75.     root.update()
  76. 0
  77. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement