You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
87 lines
2.6 KiB
87 lines
2.6 KiB
extends Node2D
|
|
|
|
const min_continent = 5
|
|
const max_contient = 5
|
|
const min_area = 0.2
|
|
const max_area = 2.0
|
|
const min_ratio = -1.0
|
|
const max_ratio = 1.0
|
|
const ocean_ratio = 1.0 / 3.0
|
|
const world_width = 1024.0
|
|
const world_height = 512.0
|
|
const nbr_rect_position = 100
|
|
const max_intersection_area = 10000.0
|
|
|
|
var world = Rect2(0.0,0.0,world_width,world_height)
|
|
var world_area = world_width * world_height
|
|
var nbr_continent
|
|
var list_continents = []
|
|
var list_rect_continents = []
|
|
|
|
func init_world():
|
|
var rng = RandomNumberGenerator.new()
|
|
|
|
var continents_area = world_area * (1.0 - ocean_ratio)
|
|
var total_area = 0.0
|
|
var list_other_continents = []
|
|
|
|
rng.randomize()
|
|
|
|
nbr_continent = rng.randi_range(min_continent,max_contient)
|
|
|
|
for i in nbr_continent:
|
|
var continent = {}
|
|
continent["area"] = rng.randf_range(min_area,max_area)
|
|
continent["ratio"] = exp(rng.randf_range(min_ratio,max_ratio))
|
|
continent["width"] = 0.0
|
|
continent["height"] = 0.0
|
|
continent["x"] = 0.0
|
|
continent["y"] = 0.0
|
|
total_area += continent["area"]
|
|
list_continents.append(continent)
|
|
|
|
# print("Total area : %f\n" % [total_area])
|
|
|
|
for continent in list_continents:
|
|
continent["area"] = (continent["area"] * continents_area / total_area)
|
|
continent["height"] = sqrt(continent["area"] / continent["ratio"])
|
|
continent["width"] = continent["area"] / continent["height"]
|
|
var rect_continent
|
|
var selected_rect_continent
|
|
var min_intersection_area = 99999999.99
|
|
|
|
for i in nbr_rect_position:
|
|
print("A")
|
|
var intersection_area = 0.0
|
|
|
|
var x = rng.randf_range(0.0,world_width - continent["width"])
|
|
var y = rng.randf_range(0.0,world_height - continent["height"])
|
|
|
|
rect_continent = Rect2(x, y, continent["width"], continent["height"])
|
|
|
|
for other_continent in list_other_continents:
|
|
var rect_other_continent = Rect2(other_continent["x"], other_continent["y"], other_continent["width"], other_continent["height"])
|
|
if rect_continent.intersects(rect_other_continent):
|
|
# print("Ok intersection\n")
|
|
intersection_area += rect_continent.intersection(rect_other_continent).get_area()
|
|
|
|
if intersection_area < min_intersection_area:
|
|
min_intersection_area = intersection_area
|
|
continent["x"] = x
|
|
continent["y"] = y
|
|
|
|
list_other_continents.append(continent)
|
|
list_rect_continents.append(Rect2(continent["x"], continent["y"], continent["width"], continent["height"]))
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready():
|
|
print("Génération des continents")
|
|
init_world()
|
|
queue_redraw()
|
|
|
|
|
|
func _draw():
|
|
draw_rect(world,Color("red"))
|
|
for rect_continent in list_rect_continents:
|
|
draw_rect(rect_continent, Color("blue"), false)
|
|
|
|
|