Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # support files ["asc_map.txt","sos.png","mobs2.png"]
- # https://www.mediafire.com/?iib1yemym7k8k71
- from PIL import Image, ImageDraw
- def mob_ok():
- with open("asc_map.txt") as f:
- for l in f.readlines():
- for c in l:
- if c == ".": #plains
- yield 0
- elif c == "-": #shrub
- yield 0
- elif c == "|": #tree
- yield 0
- elif c == "^": #water
- yield 1
- elif c == "%": #lava
- yield 2
- elif c == "#": #mountains
- yield 2
- elif c == "T": #town
- yield 2
- elif c == "C": #castle
- yield 2
- elif c == "D": #dungeon
- yield 2
- else: #if c == "\n":
- pass
- def shift_mob(x, y, type, ok_map=list(mob_ok())):
- i = x + 64*y
- while ok_map[i] != type:
- i += 1
- y,x = divmod(i,64)
- return x,y
- def pos_gen(start=0x0e,level=5):
- rng = start
- lvl_chart = [[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
- [0,0,0,0,0,0,0,0,2,2,2,2,2,2,2,2,2,2,2,4,4,4,4,4,4,3,3,3,5,1],]
- for i,t in enumerate(lvl_chart[level//5]):
- rng = (185*rng-6)%256
- x = rng//4
- rng = (185*rng-6)%256
- y = rng//4
- x,y = shift_mob(x,y,t%2)
- yield i,t,x,y,rng
- world = Image.open("sos.png")
- d = ImageDraw.Draw(world)
- def add_mob(x, y, t, i, border=False, mobs=Image.open("mobs2.png")):
- mob = mobs.crop((16*t, 0, 16*(t+1), 16))
- source = mob.split()
- mask = source[1].point(lambda i: i != 0x80 and 255)
- rect = (16*x,16*y,16*(x+1),16*(y+1))
- if border is True:
- if i < 27:
- rg,b = divmod(i,3)
- r,g = divmod(rg,3)
- color = (r*128,g*128,b*128)
- d.rectangle(rect, outline=color)
- world.paste(mob, rect, mask)
- def rng_gen(seed=0, stop=None):
- if stop is None:
- stop = seed
- a = seed
- while True:
- yield a
- a = (17*a + 23)%256
- if a == stop:
- break
- rng_map = {n:i for i,n in enumerate(rng_gen())}
- for index_in,rng_in in enumerate(rng_gen()):
- world = Image.open("sos.png")
- for i,t,x,y,rng_out in pos_gen(rng_in):
- add_mob(x,y,t,i)
- index_out = rng_map[rng_out]
- out_name = "L5\{:02x}_{:02x}_{:02x}_{:02x}.png".format(index_in,rng_in,rng_out,index_out,)
- world.save(out_name)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement