Browse Source

Added option for color.

master
Noëlle Anthony 7 years ago
parent
commit
d4cba27329
2 changed files with 13 additions and 4 deletions
  1. 1
    0
      README.md
  2. 12
    4
      procgen.py

+ 1
- 0
README.md View File

@@ -13,6 +13,7 @@ It takes the following flags:
* --birth *x*: if an empty cell has more than this many wall cells surrounding it, it becomes a wall. *x* must be an integer from 1-8.
* --reps *x*: the number of smoothing passes to take on the map. *x* must be a positive integer. Large values can significantly extend runtime.
* --out: save the result to an image in the maps/ directory instead of printing it to the screen.
* --color: uses random complementary colors in the saved image instead of black and white. *Does nothing if not used with the --out flag.*

### A note on width and height


+ 12
- 4
procgen.py View File

@@ -63,7 +63,7 @@ def printDungeon(d_map, wall=None, path=None):
print("".join([wall if x == True else path for x in line]))
print()

def main(x=None, y=None, seed=None, d_lmt=None, a_lmt=None, reps=None, out=None):
def main(x=None, y=None, seed=None, d_lmt=None, a_lmt=None, reps=None, out=None, color=None):
# Initialize
x = 20 if x == None else int(x)
y = 20 if y == None else int(y)
@@ -72,6 +72,7 @@ def main(x=None, y=None, seed=None, d_lmt=None, a_lmt=None, reps=None, out=None)
a_lmt = 4 if a_lmt == None else int(a_lmt)
reps = 2 if reps == None else int(reps)
out = False if out == None else bool(out)
color = False if color == None else bool(color)
my_map = createDungeon(x,y,seed)
if not out:
printDungeon(my_map)
@@ -82,9 +83,12 @@ def main(x=None, y=None, seed=None, d_lmt=None, a_lmt=None, reps=None, out=None)
if out:
img = Image.new("RGB",(x,y),(0,0,0))
lst = []
c_wall = [r.randint(0,255), r.randint(0,255), r.randint(0,255)] if color else [0,0,0]
c_space = [255-x for x in c_wall]

for line in my_map:
for val in line:
lst.append((0,0,0) if val else (255,255,255))
lst.append(tuple(c_space) if val else tuple(c_wall))
img.putdata(lst)
hexes = ["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"]
filename = []
@@ -103,12 +107,15 @@ def parseArgs(args):
"--death" : 4,
"--birth" : 4,
"--reps" : 2,
"--out" : False
"--out" : False,
"--color" : False,
}
for flag, default in flags.items():
if flag in args:
if flag == "--out":
flags["--out"] = True
elif flag == "--color":
flags["--color"] = True
else:
flags[flag] = args[args.index(flag) + 1]
return flags
@@ -122,4 +129,5 @@ if __name__ == "__main__":
flags["--death"],
flags["--birth"],
flags["--reps"],
flags["--out"])
flags["--out"],
flags["--color"])

Loading…
Cancel
Save