diff --git a/world_maker/data/building.png b/world_maker/data/building.png index 7160ed9..fd47f44 100644 Binary files a/world_maker/data/building.png and b/world_maker/data/building.png differ diff --git a/world_maker/data/building_moutain.png b/world_maker/data/building_moutain.png new file mode 100644 index 0000000..25fedbb Binary files /dev/null and b/world_maker/data/building_moutain.png differ diff --git a/world_maker/data/city_map.png b/world_maker/data/city_map.png index a6d60e6..2dca294 100644 Binary files a/world_maker/data/city_map.png and b/world_maker/data/city_map.png differ diff --git a/world_maker/data/district.png b/world_maker/data/district.png index d8191d3..fff7286 100644 Binary files a/world_maker/data/district.png and b/world_maker/data/district.png differ diff --git a/world_maker/data/heightmap.png b/world_maker/data/heightmap.png index b961768..5da15f8 100644 Binary files a/world_maker/data/heightmap.png and b/world_maker/data/heightmap.png differ diff --git a/world_maker/data/heightmap_smooth.png b/world_maker/data/heightmap_smooth.png index e366caa..62999a1 100644 Binary files a/world_maker/data/heightmap_smooth.png and b/world_maker/data/heightmap_smooth.png differ diff --git a/world_maker/data/heightmap_with_building.png b/world_maker/data/heightmap_with_building.png new file mode 100644 index 0000000..d6902ee Binary files /dev/null and b/world_maker/data/heightmap_with_building.png differ diff --git a/world_maker/data/highwaymap.png b/world_maker/data/highwaymap.png index eda2e82..9de071a 100644 Binary files a/world_maker/data/highwaymap.png and b/world_maker/data/highwaymap.png differ diff --git a/world_maker/data/mountain_map.png b/world_maker/data/mountain_map.png index 57e7a16..67a6fe6 100644 Binary files a/world_maker/data/mountain_map.png and b/world_maker/data/mountain_map.png differ diff --git a/world_maker/data/removed_treesmap.png b/world_maker/data/removed_treesmap.png index ad74f8b..35dd1f5 100644 Binary files a/world_maker/data/removed_treesmap.png and b/world_maker/data/removed_treesmap.png differ diff --git a/world_maker/data/roadmap.png b/world_maker/data/roadmap.png index b5fbd37..3c287cc 100644 Binary files a/world_maker/data/roadmap.png and b/world_maker/data/roadmap.png differ diff --git a/world_maker/data/skeleton_highway.png b/world_maker/data/skeleton_highway.png index a486dcd..cd2f09f 100644 Binary files a/world_maker/data/skeleton_highway.png and b/world_maker/data/skeleton_highway.png differ diff --git a/world_maker/data/skeleton_highway_area.png b/world_maker/data/skeleton_highway_area.png index 4ca5c47..fd47f44 100644 Binary files a/world_maker/data/skeleton_highway_area.png and b/world_maker/data/skeleton_highway_area.png differ diff --git a/world_maker/data/skeleton_mountain.png b/world_maker/data/skeleton_mountain.png index 8b2fae1..4c93e1d 100644 Binary files a/world_maker/data/skeleton_mountain.png and b/world_maker/data/skeleton_mountain.png differ diff --git a/world_maker/data/skeleton_mountain_area.png b/world_maker/data/skeleton_mountain_area.png index dd64749..c9b40c2 100644 Binary files a/world_maker/data/skeleton_mountain_area.png and b/world_maker/data/skeleton_mountain_area.png differ diff --git a/world_maker/data/smooth_sobel_watermap.png b/world_maker/data/smooth_sobel_watermap.png index df4efa0..196fd0a 100644 Binary files a/world_maker/data/smooth_sobel_watermap.png and b/world_maker/data/smooth_sobel_watermap.png differ diff --git a/world_maker/data/smooth_terrain_delta.png b/world_maker/data/smooth_terrain_delta.png index 85e44d0..0465ede 100644 Binary files a/world_maker/data/smooth_terrain_delta.png and b/world_maker/data/smooth_terrain_delta.png differ diff --git a/world_maker/data/sobelmap.png b/world_maker/data/sobelmap.png index 2147614..7b3b89b 100644 Binary files a/world_maker/data/sobelmap.png and b/world_maker/data/sobelmap.png differ diff --git a/world_maker/data/treemap.png b/world_maker/data/treemap.png index a721eb6..3875abb 100644 Binary files a/world_maker/data/treemap.png and b/world_maker/data/treemap.png differ diff --git a/world_maker/data/watermap.png b/world_maker/data/watermap.png index 38472c6..e882724 100644 Binary files a/world_maker/data/watermap.png and b/world_maker/data/watermap.png differ diff --git a/world_maker/data_analysis.py b/world_maker/data_analysis.py index a04fa60..b5c228c 100644 --- a/world_maker/data_analysis.py +++ b/world_maker/data_analysis.py @@ -156,6 +156,30 @@ def subtract_map(image: Union[str, Image], substractImage: Union[str, Image]) -> return Image.fromarray(array_heightmap) +def overide_map(base: Image, top: Image) -> Image: + base = handle_import_image(base).convert('L') + top = handle_import_image(top).convert('L') + + width, height = base.size + + if top.size != (width, height): + raise ValueError("Mismatching images sizes") + + result_image = Image.new('L', (width, height)) + + for x in range(width): + for y in range(height): + pixel1 = base.getpixel((x, y)) + pixel2 = top.getpixel((x, y)) + + if pixel1 != 0: + result_image.putpixel((x, y), pixel1) + else: + result_image.putpixel((x, y), pixel2) + + return result_image + + def group_map(image1: Union[str, Image], image2: Union[str, Image]) -> Image: image1 = handle_import_image(image1).convert('L') image2 = handle_import_image(image2).convert('L') diff --git a/world_maker/pack_rectangle.py b/world_maker/pack_rectangle.py index 6f2a8b0..79afe60 100644 --- a/world_maker/pack_rectangle.py +++ b/world_maker/pack_rectangle.py @@ -29,7 +29,8 @@ class Bin: best_spot_empty_area = empty_area if best_spot is not None: - self.rectangles.append((best_spot, (best_spot[0] + rectangle.width, best_spot[1] + rectangle.height))) + self.rectangles.append( + (best_spot, (best_spot[0] + rectangle.width, best_spot[1] + rectangle.height))) self.update_grid(rectangle, *best_spot) return True @@ -57,7 +58,8 @@ class Bin: def pack_rectangles(rectangles, grid): - rectangles = sorted(rectangles, key=lambda r: r.width * r.height, reverse=True) + rectangles = sorted( + rectangles, key=lambda r: r.width * r.height, reverse=True) bins = [Bin(grid)] for rectangle in rectangles: @@ -90,21 +92,23 @@ def pack_rectangles(grid, min_width: int = 10, max_width: int = 25): return bin.rectangles -def draw_rectangles(rectangles, grid): - image = Image.new('RGB', (len(grid[0]), len(grid)), (0, 0, 0)) +def draw_rectangles(rectangles, grid, heightmap): + heightmap = handle_import_image(heightmap).convert('L') + image = Image.new('L', (len(grid[0]), len(grid)), (0)) for rectangle in rectangles: start, end = rectangle for x in range(start[0], end[0]): for y in range(start[1], end[1]): - image.putpixel((x, y), (144, 255, 144)) + image.putpixel((x, y), heightmap.getpixel((x, y))) return image -def generate_building(image: Union[str, Image], min_width: int = 10, max_width: int = 25): +def generate_building(image: Union[str, Image], heightmap: Union[str, Image], output: str = './world_maker/data/building.png', min_width: int = 10, max_width: int = 25): image = handle_import_image(image).convert('L') grid = np.array(image) rectangles = pack_rectangles(grid, min_width, max_width) - draw_rectangles(rectangles, grid).save('./world_maker/data/building.png') + draw_rectangles(rectangles, grid, heightmap).save( + output) return rectangles diff --git a/world_maker/terraforming.py b/world_maker/terraforming.py index 2b567e8..72ff6e2 100644 --- a/world_maker/terraforming.py +++ b/world_maker/terraforming.py @@ -9,7 +9,7 @@ from world_maker.data_analysis import handle_import_image def remove_trees(heightmap: Union[str, Image], treesmap: Union[str, Image], mask: Union[str, Image]): - print(["Remove tree"] Starting...) + print("[Remove tree] Starting...") editor = Editor(buffering=True) build_area = editor.getBuildArea() build_rectangle = build_area.toRect() @@ -44,7 +44,6 @@ def remove_trees(heightmap: Union[str, Image], treesmap: Union[str, Image], mask for x in range(0, distance[0]): for z in range(0, distance[1]): - print("removing tree in ", start[0] + x, start[1] + z) if removed_treesmap.getpixel((x, z)) != 0: y = heightmap.getpixel((x, z)) y_top = removed_treesmap.getpixel((x, z)) @@ -52,12 +51,12 @@ def remove_trees(heightmap: Union[str, Image], treesmap: Union[str, Image], mask editor, (start[0] + x, y+1, start[1] + z), (start[0] + x, y_top, start[1] + z), Block('air')) removed_treesmap.save('./world_maker/data/removed_treesmap.png') - print(["Remove tree"] Done.) + print("[Remove tree] Done.") def smooth_terrain(heightmap: Union[str, Image], heightmap_smooth: Union[str, Image], mask: Union[str, Image]): - print(["Smooth terrain"] Starting...) + print("[Smooth terrain] Starting...") editor = Editor() build_area = editor.getBuildArea() build_rectangle = build_area.toRect() @@ -99,4 +98,4 @@ def smooth_terrain(heightmap: Union[str, Image], heightmap_smooth: Union[str, Im editor, (start[0] + x, y, start[1] + z), (start[0] + x, y_smooth, start[1] + z), block) smooth_terrain_delta.save('./world_maker/data/smooth_terrain_delta.png') - print(["Smoothing terrain"] Done.) + print("[Smooth terrain] Done.") diff --git a/world_maker/world_maker.py b/world_maker/world_maker.py index 5ac439a..2210234 100644 --- a/world_maker/world_maker.py +++ b/world_maker/world_maker.py @@ -1,7 +1,7 @@ from world_maker.World import World from PIL import Image from world_maker.data_analysis import (get_data, filter_negative, rectangle_2D_to_3D, skeleton_mountain_map, highway_map, filter_sobel, skeleton_highway_map, - smooth_sobel_water, subtract_map, detect_mountain, filter_smooth) + smooth_sobel_water, subtract_map, detect_mountain, filter_smooth, overide_map) from world_maker.City import City from world_maker.Position import Position from random import randint @@ -34,7 +34,9 @@ def world_maker(): './world_maker/data/skeleton_highway_area.png').save('./world_maker/data/city_map.png') subtract_map('./world_maker/data/city_map.png', './world_maker/data/mountain_map.png').save('./world_maker/data/city_map.png') - rectangle_building = generate_building('./world_maker/data/city_map.png') + + rectangle_building = generate_building( + './world_maker/data/city_map.png', './world_maker/data/heightmap.png', output='./world_maker/data/building.png') rectangle_building = rectangle_2D_to_3D(rectangle_building) skeleton_mountain = skeleton_mountain_map(image_mountain_map) @@ -43,6 +45,12 @@ def world_maker(): subtract_map(smooth_sobel_water_map, filter_negative( './world_maker/data/mountain_map.png')).save('./world_maker/data/mountain_map.png') rectangle_mountain = generate_building( - './world_maker/data/mountain_map.png') + './world_maker/data/mountain_map.png', './world_maker/data/heightmap.png', output='./world_maker/data/building_moutain.png') rectangle_mountain = rectangle_2D_to_3D(rectangle_mountain) + + # Terraforming + overide_map('./world_maker/data/heightmap.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') return rectangle_mountain, rectangle_building, skeleton_highway, skeleton_mountain, road_grid