Add get_data_no_update to quick test

This commit is contained in:
2024-06-24 16:00:44 +02:00
parent 107b3e08c4
commit 0872cb1901
14 changed files with 61 additions and 43 deletions

36
main.py
View File

@@ -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):

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 717 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1005 B

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.9 KiB

After

Width:  |  Height:  |  Size: 6.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.5 KiB

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 45 KiB

After

Width:  |  Height:  |  Size: 45 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 44 KiB

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@@ -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)
@@ -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

View File

@@ -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')