Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_2D_Terrain_Gen.py -- too slow
- from Tkinter import *
- from PIL import Image, ImageTk
- import random
- import time
- w = h = 200
- pp = [(x,y) for x in xrange(w) for y in xrange(h)]
- random.shuffle(pp)
- __xy = [z%254 for z in xrange(w*h)]
- __xy.sort()
- v = __xy.index(20)
- xy = []
- for z in xrange(0,w*h,v):
- t = __xy[z-v:z]
- v = max(0,v-5)
- random.shuffle(t)
- xy.extend(t)
- def climb(x,y):
- t = x%2 # to double the speed
- if t:
- z = [(x+1, y), (x, y+1), (x, y-1), (x-1, y)]
- else:
- z = [(x+1, y+1), (x+1, y-1), (x-1, y+1), (x-1, y-1)]
- random.shuffle(z)
- return z
- root = Tk()
- root.title("Tk 2D Terrain Gen")
- canvas = Canvas(root, width=w, height=h, bg='black')
- canvas.pack()
- peaks = 10
- rnd_peaks = [0 for z in range(1,w*h)]+range(1,10)+[1]
- random.shuffle(rnd_peaks)
- zzz,pp = pp[:peaks],pp[peaks:]
- aaa = zzz[:]
- t = 0
- p = 2
- print v
- while 1:
- if aaa:
- x,y = aaa.pop(0)
- try:
- ccc = '#%02x%02x%02x' % tuple([xy.pop()]*3)
- except:
- break
- canvas.create_line((x,y,x+1,y), fill=ccc)
- ppp = climb(x,y)
- for z in ppp[:p]:
- try:
- aaa.append(pp.pop(pp.index(z)))
- except:
- 0
- for z in ppp[p:]:
- try:
- zzz.append(pp.pop(pp.index(z)))
- except:
- 0
- if rnd_peaks.pop():
- aaa = [pp.pop()] + aaa
- else:
- aaa,zzz = zzz[:400],zzz[400:]
- random.shuffle(aaa)
- if t < time.time():
- print len(pp)
- t = time.time()+5
- if len(pp) < w*h*0.5:
- p = 1
- root.update()
- 0
- print '***'
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement