-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
57 lines (43 loc) · 1.52 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import png
import world
import argparse
class Main:
def __init__(self):
self.w = 512
self.h = 512
self.pixels = None
self.base = 0
def main(self):
self.parse_args()
self.create_pixels()
self.save_image()
def parse_args(self):
parser = argparse.ArgumentParser()
parser.add_argument("-b", "--base", help="base for the noise function", type=int, default=0)
parser.add_argument("-x", "--width", help="width of the world map", type=int, default=512)
parser.add_argument("-y", "--height", help="height of the world map", type=int, default=512)
args = parser.parse_args()
self.base = args.base
self.w = args.width
self.h = args.height
def create_pixels(self):
"""
Create the pixel array that can be saved as a png. The pixels
are computed from a `world` generator; see `world` module.
"""
self.pixels = []
world_generator = world.world1(self.w, self.h, self.base)
try:
for vertical in range(self.h):
row = []
for horizontal in range(self.w):
value = next(world_generator) * 255
row.append( [value, value, value] )
self.pixels.append(row)
except StopIteration:
pass
def save_image(self, filename="world.png"):
image = png.from_array(self.pixels, 'RGB')
image.save(filename)
if __name__ == '__main__':
Main().main()