Tweak world generation
e27f0fb5aad9363e1d57b7ea25effeb7bd235316
This commit is contained in:
parent
0c16637901
commit
845b13650a
2 changed files with 30 additions and 11 deletions
|
@ -177,18 +177,23 @@ impl World {
|
||||||
let value_5 =
|
let value_5 =
|
||||||
self.random_noise_from_polar_coordinates(alpha, beta, RADIUS_5, offset_5)?;
|
self.random_noise_from_polar_coordinates(alpha, beta, RADIUS_5, offset_5)?;
|
||||||
|
|
||||||
let value = self.mountain_range_noise_from_random_noise(mix_values(
|
let value = continent_value;
|
||||||
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 = mix_values(value, value_3, Self::TERRAIN_NOISE_FACTOR_1);
|
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_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(())
|
Ok(())
|
||||||
|
|
|
@ -15,14 +15,14 @@ impl WorldManager {
|
||||||
}
|
}
|
||||||
pub fn new_world(&mut self) -> Result<&World, WorldGenError> {
|
pub fn new_world(&mut self) -> Result<&World, WorldGenError> {
|
||||||
let seed = random();
|
let seed = random();
|
||||||
let mut new_world = World::new(800, 600, seed);
|
let mut new_world = World::new(400, 200, seed);
|
||||||
new_world.generate()?;
|
new_world.generate()?;
|
||||||
self.world = Some(new_world);
|
self.world = Some(new_world);
|
||||||
Ok(self.get_world().unwrap())
|
Ok(self.get_world().unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn generate_color(cell: &TerrainCell) -> Color {
|
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 rainfall_color = Self::rainfall_color(cell.rainfall);
|
||||||
|
|
||||||
let normalized_rainfall = f32::max(cell.rainfall / World::MAX_RAINFALL, 0.0);
|
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 {
|
fn rainfall_color(rainfall: f32) -> Color {
|
||||||
if rainfall < 0.0 {
|
if rainfall < 0.0 {
|
||||||
Color::BLACK
|
Color::BLACK
|
||||||
|
|
Loading…
Reference in a new issue