Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_rainbow_island_gen.py -- slow
- from Tkinter import *
- from PIL import Image, ImageTk
- from math import *
- import random
- import re
- import time
- w = h = 200
- vxy = (1533.0)/(w*h)
- print vxy
- rainbow=[]
- def z(r,g,b):
- rainbow.append((r,g,b))
- r,g,b=255,0,0
- for g in range(256):
- z(r,g,b)
- for r in range(254, -1, -1):
- z(r,g,b)
- for b in range(256):
- z(r,g,b)
- for g in range(254, -1, -1):
- z(r,g,b)
- for r in range(256):
- z(r,g,b)
- for b in range(254, -1, -1):
- z(r,g,b)
- 0
- z = rainbow.index((0,255,0))
- rainbow = rainbow[z:] + rainbow[:z]
- xy = []
- for y in range(0,h):
- for x in range(0,w):
- xy.append([x,y])
- random.shuffle(xy)
- def mv():
- if zzz:
- x,y = zzz[0]
- canvas.create_line((x,y,x+1,y+1),fill='#%02x%02x%02x' % rainbow[int(len(xy)*vxy)])
- 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],
- [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]]
- random.shuffle(climb)
- climb = climb[:6]
- for z in climb:
- try:
- zzz.append(xy.pop(xy.index(z)))
- x,y = z
- canvas.create_line((x,y,x+1,y+1), fill='#%02x%02x%02x' % rainbow[int(len(xy)*vxy)])
- except:
- 0
- 0
- root = Tk()
- root.title("Tk Rainbow Island Gen")
- canvas = Canvas(root, width=w, height=h)
- canvas.pack()
- peaks = 6
- zzz,xy = xy[:peaks],xy[peaks:]
- t = 0
- while zzz:
- zzz,z = zzz[:6],zzz[6:]
- random.shuffle(zzz)
- zzz = zzz+z
- mv()
- zzz.pop(0)
- if t < time.time():
- t = time.time()+10
- print len(xy)
- root.update()
- 0
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement