diff --git a/main.py b/main.py index 02eacac..abad2a8 100644 --- a/main.py +++ b/main.py @@ -55,25 +55,25 @@ def main(): entranceDirection = ["N", "S", "E", "W"] - for houses in rectangle_building: - height = get_height_building_from_center( - center, (houses[0][0], houses[0][2]), length_world) - start = (houses[0][0] + origin[0], houses[0] - [1], houses[0][2] + origin[1]) - end = (houses[1][0] + origin[0], houses[1] - [1] + height, houses[1][2] + origin[1]) - house = House(editor, start, end, - entranceDirection[random.randint(0, 3)], blocks) - house.build() + # for houses in rectangle_building: + # height = get_height_building_from_center( + # center, (houses[0][0], houses[0][2]), length_world) + # start = (houses[0][0] + origin[0], houses[0] + # [1], houses[0][2] + origin[1]) + # end = (houses[1][0] + origin[0], houses[1] + # [1] + height, houses[1][2] + origin[1]) + # house = House(editor, start, end, + # entranceDirection[random.randint(0, 3)], blocks) + # house.build() - for houses in rectangle_house_mountain: - start = (houses[0][0] + origin[0], houses[0] - [1], houses[0][2] + origin[1]) - end = (houses[1][0] + origin[0], houses[1] - [1], houses[1][2] + origin[1]) - house = House(editor, start, end, - entranceDirection[random.randint(0, 3)], blocks) - house.build() + # for houses in rectangle_house_mountain: + # start = (houses[0][0] + origin[0], houses[0] + # [1], houses[0][2] + origin[1]) + # end = (houses[1][0] + origin[0], houses[1] + # [1], houses[1][2] + origin[1]) + # house = House(editor, start, end, + # entranceDirection[random.randint(0, 3)], blocks) + # house.build() def get_height_building_from_center(center, position, length_world): diff --git a/world_maker/data/building.png b/world_maker/data/building.png index dfff8fe..4a17fac 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 index 2ccbfd6..f368aea 100644 Binary files a/world_maker/data/building_moutain.png 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 bf2603c..db0f628 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 392b888..38652dd 100644 Binary files a/world_maker/data/district.png and b/world_maker/data/district.png differ diff --git a/world_maker/data/heightmap_smooth.png b/world_maker/data/heightmap_smooth.png index a56dd90..1991fef 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 index ba934ac..e13f0e4 100644 Binary files a/world_maker/data/heightmap_with_building.png and b/world_maker/data/heightmap_with_building.png differ diff --git a/world_maker/data/mountain_map.png b/world_maker/data/mountain_map.png index 80e9c97..8b8acd3 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/roadmap.png b/world_maker/data/roadmap.png index 82cdef4..2fca289 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 47e32f8..0b985de 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_mountain.png b/world_maker/data/skeleton_mountain.png index 6108ffc..7fe9f8f 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 c922f92..f72239c 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_analysis.py b/world_maker/data_analysis.py index 477f085..c7180d7 100644 --- a/world_maker/data_analysis.py +++ b/world_maker/data_analysis.py @@ -18,6 +18,17 @@ def get_data(world: World): return heightmap, watermap, treemap +def get_data_no_update(): + print("[Data Analysis] Generating data...") + # heightmap, watermap, treemap = world.getData() + heightmap, watermap, treemap = handle_import_image( + './world_maker/data/heightmap.png'), handle_import_image( + './world_maker/data/watermap.png'), handle_import_image( + './world_maker/data/treemap.png') + print("[Data Analysis] Data generated.") + return heightmap, watermap, treemap + + def handle_import_image(image: str | Image.Image) -> Image.Image: if isinstance(image, str): return Image.open(image) @@ -68,29 +79,29 @@ def filter_sobel(image: str | Image.Image) -> Image.Image: for i in range(1, h - 1): for j in range(1, w - 1): horizontalGrad = ( - (horizontal[0, 0] * gray_img[i - 1, j - 1]) - + (horizontal[0, 1] * gray_img[i - 1, j]) - + (horizontal[0, 2] * gray_img[i - 1, j + 1]) - + (horizontal[1, 0] * gray_img[i, j - 1]) - + (horizontal[1, 1] * gray_img[i, j]) - + (horizontal[1, 2] * gray_img[i, j + 1]) - + (horizontal[2, 0] * gray_img[i + 1, j - 1]) - + (horizontal[2, 1] * gray_img[i + 1, j]) - + (horizontal[2, 2] * gray_img[i + 1, j + 1]) + (horizontal[0, 0] * gray_img[i - 1, j - 1]) + + (horizontal[0, 1] * gray_img[i - 1, j]) + + (horizontal[0, 2] * gray_img[i - 1, j + 1]) + + (horizontal[1, 0] * gray_img[i, j - 1]) + + (horizontal[1, 1] * gray_img[i, j]) + + (horizontal[1, 2] * gray_img[i, j + 1]) + + (horizontal[2, 0] * gray_img[i + 1, j - 1]) + + (horizontal[2, 1] * gray_img[i + 1, j]) + + (horizontal[2, 2] * gray_img[i + 1, j + 1]) ) newhorizontalImage[i - 1, j - 1] = abs(horizontalGrad) verticalGrad = ( - (vertical[0, 0] * gray_img[i - 1, j - 1]) - + (vertical[0, 1] * gray_img[i - 1, j]) - + (vertical[0, 2] * gray_img[i - 1, j + 1]) - + (vertical[1, 0] * gray_img[i, j - 1]) - + (vertical[1, 1] * gray_img[i, j]) - + (vertical[1, 2] * gray_img[i, j + 1]) - + (vertical[2, 0] * gray_img[i + 1, j - 1]) - + (vertical[2, 1] * gray_img[i + 1, j]) - + (vertical[2, 2] * gray_img[i + 1, j + 1]) + (vertical[0, 0] * gray_img[i - 1, j - 1]) + + (vertical[0, 1] * gray_img[i - 1, j]) + + (vertical[0, 2] * gray_img[i - 1, j + 1]) + + (vertical[1, 0] * gray_img[i, j - 1]) + + (vertical[1, 1] * gray_img[i, j]) + + (vertical[1, 2] * gray_img[i, j + 1]) + + (vertical[2, 0] * gray_img[i + 1, j - 1]) + + (vertical[2, 1] * gray_img[i + 1, j]) + + (vertical[2, 2] * gray_img[i + 1, j + 1]) ) newverticalImage[i - 1, j - 1] = abs(verticalGrad) @@ -318,6 +329,7 @@ def get_index_of_biggest_area_mountain(area_mountain: list[int], exception: list index = i return index + def get_random_point_in_area_mountain(mountain_map: list[list[int]], index: int) -> Position | None: points = [] for y in range(len(mountain_map)): @@ -328,6 +340,7 @@ def get_random_point_in_area_mountain(mountain_map: list[list[int]], index: int) return None return choice(points) + def get_center_of_area_mountain(mountain_map: list[list[int]], index: int) -> Position: sum_x = 0 sum_y = 0 @@ -353,7 +366,8 @@ def detect_mountain(number_of_mountain: int = 2, height_threshold: int = 10, for y in range(image_heightmap.size[1]): for x in range(image_heightmap.size[0]): avg_height += image_heightmap.getpixel((x, y)) - avg_height = int(avg_height / (image_heightmap.size[0] * image_heightmap.size[1])) + avg_height = int( + avg_height / (image_heightmap.size[0] * image_heightmap.size[1])) print("[Data Analysis] Average height:", avg_height) mountain_map = [[-1 if image_heightmap.getpixel((x, y)) < (avg_height + height_threshold) else 0 for x in @@ -375,13 +389,15 @@ def detect_mountain(number_of_mountain: int = 2, height_threshold: int = 10, if number_of_mountain < len(area_mountain): index_mountain = [] for n in range(number_of_mountain): - index_mountain.append(get_index_of_biggest_area_mountain(area_mountain, index_mountain)) + index_mountain.append(get_index_of_biggest_area_mountain( + area_mountain, index_mountain)) else: index_mountain = [i for i in range(len(area_mountain))] position_mountain = [] for i in range(len(index_mountain)): - position_mountain.append(get_center_of_area_mountain(mountain_map, index_mountain[i])) + position_mountain.append(get_center_of_area_mountain( + mountain_map, index_mountain[i])) return position_mountain @@ -408,7 +424,7 @@ def rectangle_2D_to_3D(rectangle: list[tuple[tuple[int, int], tuple[int, int]]], def transpose_form_heightmap(heightmap: str | Image.Image, coordinates, origin: tuple[int, int]) -> tuple[ - int, int, int]: + int, int, int]: heightmap = handle_import_image(heightmap).convert('L') xMin, zMin = origin diff --git a/world_maker/world_maker.py b/world_maker/world_maker.py index 2e5a7ca..a108feb 100644 --- a/world_maker/world_maker.py +++ b/world_maker/world_maker.py @@ -1,6 +1,6 @@ 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, +from world_maker.data_analysis import (get_data, get_data_no_update, 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, overide_map) from world_maker.City import City from world_maker.Position import Position @@ -9,8 +9,10 @@ from world_maker.pack_rectangle import generate_building def world_maker(): - world = World() - heightmap, watermap, treemap = get_data(world) + # world = World() + # heightmap, watermap, treemap = get_data(world) + + heightmap, watermap, treemap = get_data_no_update() filter_sobel( "./world_maker/data/heightmap.png").save('./world_maker/data/sobelmap.png')