Add smooth building terrain
|
Before Width: | Height: | Size: 128 B After Width: | Height: | Size: 153 B |
|
Before Width: | Height: | Size: 217 B After Width: | Height: | Size: 113 B |
|
Before Width: | Height: | Size: 432 B After Width: | Height: | Size: 428 B |
|
Before Width: | Height: | Size: 3.0 KiB After Width: | Height: | Size: 3.3 KiB |
|
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.7 KiB |
|
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 2.1 KiB |
|
Before Width: | Height: | Size: 77 B After Width: | Height: | Size: 126 B |
|
Before Width: | Height: | Size: 602 B After Width: | Height: | Size: 755 B |
|
Before Width: | Height: | Size: 133 B After Width: | Height: | Size: 873 B |
|
Before Width: | Height: | Size: 2.9 KiB After Width: | Height: | Size: 3.1 KiB |
|
Before Width: | Height: | Size: 3.8 KiB After Width: | Height: | Size: 4.5 KiB |
|
Before Width: | Height: | Size: 462 B After Width: | Height: | Size: 595 B |
|
Before Width: | Height: | Size: 648 B After Width: | Height: | Size: 590 B |
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 3.3 KiB After Width: | Height: | Size: 3.8 KiB |
|
Before Width: | Height: | Size: 348 B After Width: | Height: | Size: 6.1 KiB |
|
Before Width: | Height: | Size: 249 B After Width: | Height: | Size: 214 B |
@@ -169,13 +169,13 @@ def overide_map(base: Image, top: Image) -> Image:
|
|||||||
|
|
||||||
for x in range(width):
|
for x in range(width):
|
||||||
for y in range(height):
|
for y in range(height):
|
||||||
pixel1 = base.getpixel((x, y))
|
base_pixel = base.getpixel((x, y))
|
||||||
pixel2 = top.getpixel((x, y))
|
top_pixel = top.getpixel((x, y))
|
||||||
|
|
||||||
if pixel1 != 0:
|
if top_pixel != 0:
|
||||||
result_image.putpixel((x, y), pixel1)
|
result_image.putpixel((x, y), top_pixel)
|
||||||
else:
|
else:
|
||||||
result_image.putpixel((x, y), pixel2)
|
result_image.putpixel((x, y), base_pixel)
|
||||||
|
|
||||||
return result_image
|
return result_image
|
||||||
|
|
||||||
@@ -247,7 +247,8 @@ def create_volume(surface: np.ndarray, heightmap: np.ndarray, make_it_flat: bool
|
|||||||
|
|
||||||
def convert_2D_to_3D(image: Union[str, Image], make_it_flat: bool = False) -> np.ndarray:
|
def convert_2D_to_3D(image: Union[str, Image], make_it_flat: bool = False) -> np.ndarray:
|
||||||
image = handle_import_image(image)
|
image = handle_import_image(image)
|
||||||
heightmap = Image.open('./world_maker/data/heightmap.png').convert('L')
|
heightmap = Image.open(
|
||||||
|
'./world_maker/data/heightmap_smooth.png').convert('L')
|
||||||
heightmap = np.array(heightmap)
|
heightmap = np.array(heightmap)
|
||||||
surface = np.array(image)
|
surface = np.array(image)
|
||||||
volume = create_volume(surface, heightmap, make_it_flat)
|
volume = create_volume(surface, heightmap, make_it_flat)
|
||||||
|
|||||||
@@ -97,9 +97,14 @@ def draw_rectangles(rectangles, grid, heightmap):
|
|||||||
image = Image.new('L', (len(grid[0]), len(grid)), (0))
|
image = Image.new('L', (len(grid[0]), len(grid)), (0))
|
||||||
for rectangle in rectangles:
|
for rectangle in rectangles:
|
||||||
start, end = rectangle
|
start, end = rectangle
|
||||||
|
height = []
|
||||||
for x in range(start[0], end[0]):
|
for x in range(start[0], end[0]):
|
||||||
for y in range(start[1], end[1]):
|
for y in range(start[1], end[1]):
|
||||||
image.putpixel((x, y), heightmap.getpixel((x, y)))
|
height.append(heightmap.getpixel((x, y)))
|
||||||
|
height_average = sum(height)/len(height)
|
||||||
|
for x in range(start[0], end[0]):
|
||||||
|
for y in range(start[1], end[1]):
|
||||||
|
image.putpixel((x, y), round(height_average))
|
||||||
return image
|
return image
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -12,9 +12,6 @@ def world_maker():
|
|||||||
world = World()
|
world = World()
|
||||||
heightmap, watermap, treemap = get_data(world)
|
heightmap, watermap, treemap = get_data(world)
|
||||||
|
|
||||||
filter_smooth(
|
|
||||||
'./world_maker/data/heightmap.png', 4).save('./world_maker/data/heightmap_smooth.png')
|
|
||||||
|
|
||||||
filter_sobel(
|
filter_sobel(
|
||||||
"./world_maker/data/heightmap.png").save('./world_maker/data/sobelmap.png')
|
"./world_maker/data/heightmap.png").save('./world_maker/data/sobelmap.png')
|
||||||
|
|
||||||
@@ -53,4 +50,18 @@ def world_maker():
|
|||||||
'./world_maker/data/building_moutain.png').save('./world_maker/data/heightmap_with_building.png')
|
'./world_maker/data/building_moutain.png').save('./world_maker/data/heightmap_with_building.png')
|
||||||
overide_map('./world_maker/data/heightmap_with_building.png',
|
overide_map('./world_maker/data/heightmap_with_building.png',
|
||||||
'./world_maker/data/building.png').save('./world_maker/data/heightmap_with_building.png')
|
'./world_maker/data/building.png').save('./world_maker/data/heightmap_with_building.png')
|
||||||
|
filter_smooth(
|
||||||
|
'./world_maker/data/heightmap_with_building.png', 2).save('./world_maker/data/heightmap_smooth.png')
|
||||||
|
overide_map('./world_maker/data/heightmap_with_building.png',
|
||||||
|
'./world_maker/data/building_moutain.png').save('./world_maker/data/heightmap_with_building.png')
|
||||||
|
overide_map('./world_maker/data/heightmap_with_building.png',
|
||||||
|
'./world_maker/data/building.png').save('./world_maker/data/heightmap_with_building.png')
|
||||||
|
filter_smooth(
|
||||||
|
'./world_maker/data/heightmap_with_building.png', 2).save('./world_maker/data/heightmap_smooth.png')
|
||||||
|
overide_map('./world_maker/data/heightmap_with_building.png',
|
||||||
|
'./world_maker/data/building_moutain.png').save('./world_maker/data/heightmap_with_building.png')
|
||||||
|
overide_map('./world_maker/data/heightmap_with_building.png',
|
||||||
|
'./world_maker/data/building.png').save('./world_maker/data/heightmap_with_building.png')
|
||||||
|
filter_smooth(
|
||||||
|
'./world_maker/data/heightmap_with_building.png', 2).save('./world_maker/data/heightmap_smooth.png')
|
||||||
return rectangle_mountain, rectangle_building, skeleton_highway, skeleton_mountain, road_grid
|
return rectangle_mountain, rectangle_building, skeleton_highway, skeleton_mountain, road_grid
|
||||||
|
|||||||