Browse Source

Now allows the user to draw their map as an image file (PNG)

master
Noëlle Anthony 7 years ago
parent
commit
8971cd58a8
1 changed files with 28 additions and 6 deletions
  1. 28
    6
      procgen.py

+ 28
- 6
procgen.py View File

import random as r import random as r
import sys import sys
from PIL import Image


def createDungeon(x=None, y=None, seed=None): def createDungeon(x=None, y=None, seed=None):
""" Initializes an x by y grid. """ Initializes an x by y grid.
print("".join([wall if x == True else path for x in line])) print("".join([wall if x == True else path for x in line]))
print() print()


def main(x=None, y=None, seed=None, d_lmt=None, a_lmt=None, reps=None):
def main(x=None, y=None, seed=None, d_lmt=None, a_lmt=None, reps=None, out=None):
# Initialize # Initialize
x = 20 if x == None else int(x) x = 20 if x == None else int(x)
y = 20 if y == None else int(y) y = 20 if y == None else int(y)
d_lmt = 4 if d_lmt == None else int(d_lmt) d_lmt = 4 if d_lmt == None else int(d_lmt)
a_lmt = 4 if a_lmt == None else int(a_lmt) a_lmt = 4 if a_lmt == None else int(a_lmt)
reps = 2 if reps == None else int(reps) reps = 2 if reps == None else int(reps)
out = False if out == None else bool(out)
my_map = createDungeon(x,y,seed) my_map = createDungeon(x,y,seed)
printDungeon(my_map)
if not out:
printDungeon(my_map)
for _ in range(reps): for _ in range(reps):
my_map = refineDungeon(my_map, d_lmt, d_lmt) my_map = refineDungeon(my_map, d_lmt, d_lmt)
printDungeon(my_map)
if not out:
printDungeon(my_map)
if out:
img = Image.new("RGB",(x,y),(0,0,0))
lst = []
for line in my_map:
for val in line:
lst.append((0,0,0) if val else (255,255,255))
img.putdata(lst)
hexes = ["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"]
filename = []
for _ in range(16):
filename.append(r.choice(hexes))
img.save('maps/{}.png'.format("".join(filename)))
print("Saved maps/{}.png".format("".join(filename)))


def parseArgs(args): def parseArgs(args):
flags = { flags = {
"--seed" : 45, "--seed" : 45,
"--death" : 4, "--death" : 4,
"--birth" : 4, "--birth" : 4,
"--reps" : 2
"--reps" : 2,
"--out" : False
} }
for flag, default in flags.items(): for flag, default in flags.items():
if flag in args: if flag in args:
flags[flag] = args[args.index(flag) + 1]
if flag == "--out":
flags["--out"] = True
else:
flags[flag] = args[args.index(flag) + 1]
return flags return flags


if __name__ == "__main__": if __name__ == "__main__":
flags["--seed"], flags["--seed"],
flags["--death"], flags["--death"],
flags["--birth"], flags["--birth"],
flags["--reps"])
flags["--reps"],
flags["--out"])

Loading…
Cancel
Save