Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_perlin_scroll.py
- from tkinter import *
- from PIL import Image, ImageTk
- import random
- ri = random.randint
- ww = 600
- hh = 600
- random.seed(0)
- def rgb2hex(r,g,b):
- return '#%02X%02X%02X'%(r,g,b)
- def draw():
- image.putdata(rgb)
- photo = ImageTk.PhotoImage(image)
- canvas.create_image(0,0,image=photo,anchor=NW)
- canvas.update()
- t = [16,8,7,6,5,5,4,4,4,3,3,3,3,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1]
- ttt = []
- i = 0
- for i in range(1,25):
- for j in range(t[i]):
- ttt += [i]
- v255 = [i for i in range(256)]
- v255 = v255[1:-1]+v255[::-1]
- rgbL = len(v255)
- o255 = {}
- e = len(ttt)-1
- for i in range(256):
- o255[i] = [0]
- j = 0
- while sum(o255[i]) <= i/2:
- o255[i] += [ttt[j]]
- j += 1
- while sum(o255[i])*2 > i:
- o255[i].remove(1)
- o255[i] += o255[i][::-1]
- if sum(o255[i]) < i:
- o255[i].insert(1,1)
- o255[256+i] = [-z for z in o255[i]]
- oL = len(o255)
- PALETTE = list(o255.keys())*2
- # print (o255,oL)
- def palette():
- s = PALETTE.pop((i**j)%oL)
- PALETTE.append(s)
- return s
- root = Tk()
- root.title("Tk_perlin_scroll.py")
- root.geometry("%dx%d+0+0"%(ww,hh))
- canvas = Canvas(root, width=ww, height=hh)
- canvas.pack()
- image = Image.new("RGB", (ww,hh), (255,255,255))
- scan = [(128,128,128) for i in '.'*ww]
- rgb = []
- i = 0
- __RGB = [[],[],[]]
- while len(rgb) < ww*hh:
- for j in range(ww):
- t = []
- for k in (0,1,2):
- if not __RGB[k]:
- s = palette()
- i += 1
- __RGB[k] = o255[s][:]
- t += [v255[(scan[j][k]+__RGB[k].pop()*5)%rgbL]] #
- scan[j] = tuple(t)
- rgb.extend(scan)
- draw()
- while 1:
- rgb = rgb[ww:]
- for j in range(ww):
- t = []
- for k in (0,1,2):
- if not __RGB[k]:
- s = palette()
- i += 1
- __RGB[k] = o255[s][:]
- t += [v255[(scan[j][k]+__RGB[k].pop()*5)%rgbL]] #
- scan[j] = tuple(t)
- rgb.extend(scan)
- draw()
Add Comment
Please, Sign In to add comment