From 845b13650aabbb363de22bcacd7e9282ed6fdc2b Mon Sep 17 00:00:00 2001 From: Tobias Berger Date: Sun, 4 Sep 2022 18:57:04 +0200 Subject: [PATCH] Tweak world generation e27f0fb5aad9363e1d57b7ea25effeb7bd235316 --- save/src/world.rs | 23 ++++++++++++++--------- save/src/world_manager.rs | 18 ++++++++++++++++-- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/save/src/world.rs b/save/src/world.rs index 88b169c..13b648b 100644 --- a/save/src/world.rs +++ b/save/src/world.rs @@ -177,18 +177,23 @@ impl World { let value_5 = self.random_noise_from_polar_coordinates(alpha, beta, RADIUS_5, offset_5)?; - let value = self.mountain_range_noise_from_random_noise(mix_values( - value_1, - value_2, - Self::MOUNTAIN_RANGE_MIX_FACTOR, - )) * mix_values(1.0, continent_value, 0.3); - - let value = mix_values(value, continent_value, Self::CONTINENT_FACTOR); + let value = continent_value; let value = mix_values(value, value_3, Self::TERRAIN_NOISE_FACTOR_1); let value = value * mix_values(1.0, value_4, Self::TERRAIN_NOISE_FACTOR_2); - let value = value * mix_values(1.0, value_5, Self::TERRAIN_NOISE_FACTOR_3); + let value = + value * mix_values(1.0, value_5, Self::TERRAIN_NOISE_FACTOR_3) * 0.2 + 0.4; - self.terrain[y][x].altitude = Self::calculate_altitude(value); + let mut value_mountain = + mix_values(value_1, value_2, Self::MOUNTAIN_RANGE_MIX_FACTOR); + value_mountain = self.mountain_range_noise_from_random_noise(value_mountain); + value_mountain = mix_values(value_mountain, value_3, Self::TERRAIN_NOISE_FACTOR_1); + value_mountain = + value_mountain * mix_values(1.0, value_4, Self::TERRAIN_NOISE_FACTOR_2); + value_mountain = + value_mountain * mix_values(1.0, value_5, Self::TERRAIN_NOISE_FACTOR_3); + value_mountain = 2.0 * value_mountain * value; + + self.terrain[y][x].altitude = Self::calculate_altitude(value_mountain); } } Ok(()) diff --git a/save/src/world_manager.rs b/save/src/world_manager.rs index 5eed3d7..c7a805d 100644 --- a/save/src/world_manager.rs +++ b/save/src/world_manager.rs @@ -15,14 +15,14 @@ impl WorldManager { } pub fn new_world(&mut self) -> Result<&World, WorldGenError> { let seed = random(); - let mut new_world = World::new(800, 600, seed); + let mut new_world = World::new(400, 200, seed); new_world.generate()?; self.world = Some(new_world); Ok(self.get_world().unwrap()) } fn generate_color(cell: &TerrainCell) -> Color { - let altitude_color = Self::altitude_color(cell.altitude); + let altitude_color = Self::altitude_contour_color(cell.altitude); let rainfall_color = Self::rainfall_color(cell.rainfall); let normalized_rainfall = f32::max(cell.rainfall / World::MAX_RAINFALL, 0.0); @@ -47,6 +47,20 @@ impl WorldManager { } } + fn altitude_contour_color(altitude: f32) -> Color { + if altitude < 0.0 { + Color::rgb(0.0, 0.0, (2.0 - altitude / World::MIN_ALTITUDE) / 2.0) + } else { + let mut shade_value = 1.0; + + while shade_value > altitude / World::MAX_ALTITUDE { + shade_value -= 0.1; + } + + Color::rgb(shade_value, shade_value, shade_value) + } + } + fn rainfall_color(rainfall: f32) -> Color { if rainfall < 0.0 { Color::BLACK