def sea_depth(world, sea_level): sea_depth = [[sea_level - world.elevation['data'][y][x] for x in range(world.width)] for y in range(world.height)] for y in range(world.height): for x in range(world.width): if world.tiles_around((x, y), radius=1, predicate=world.is_land): sea_depth[y][x] = 0 elif world.tiles_around((x, y), radius=2, predicate=world.is_land): sea_depth[y][x] *= 0.3 elif world.tiles_around((x, y), radius=3, predicate=world.is_land): sea_depth[y][x] *= 0.5 elif world.tiles_around((x, y), radius=4, predicate=world.is_land): sea_depth[y][x] *= 0.7 elif world.tiles_around((x, y), radius=5, predicate=world.is_land): sea_depth[y][x] *= 0.9 sea_depth = anti_alias(sea_depth, 10) min_depth, max_depth = matrix_min_and_max(sea_depth) sea_depth = [[rescale_value(sea_depth[y][x], min_depth, max_depth, 0.0, 1.0) for x in range(world.width)] for y in range(world.height)] return sea_depth
def sea_depth(world, sea_level): sea_depth = [[ sea_level - world.elevation['data'][y][x] for x in range(world.width) ] for y in range(world.height)] for y in range(world.height): for x in range(world.width): if world.tiles_around((x, y), radius=1, predicate=world.is_land): sea_depth[y][x] = 0 elif world.tiles_around((x, y), radius=2, predicate=world.is_land): sea_depth[y][x] *= 0.3 elif world.tiles_around((x, y), radius=3, predicate=world.is_land): sea_depth[y][x] *= 0.5 elif world.tiles_around((x, y), radius=4, predicate=world.is_land): sea_depth[y][x] *= 0.7 elif world.tiles_around((x, y), radius=5, predicate=world.is_land): sea_depth[y][x] *= 0.9 sea_depth = anti_alias(sea_depth, 10) min_depth, max_depth = matrix_min_and_max(sea_depth) sea_depth = [[ rescale_value(sea_depth[y][x], min_depth, max_depth, 0.0, 1.0) for x in range(world.width) ] for y in range(world.height)] return sea_depth
def test_rescale_value(self): self.assertAlmostEqual(0.0, rescale_value(0.0, 0.0, 1.0, 0.0, 10.0)) self.assertAlmostEqual(2.5, rescale_value(0.25, 0.0, 1.0, 0.0, 10.0)) self.assertAlmostEqual(5.0, rescale_value(0.5, 0.0, 1.0, 0.0, 10.0)) self.assertAlmostEqual(7.5, rescale_value(0.75, 0.0, 1.0, 0.0, 10.0)) self.assertAlmostEqual(10.0, rescale_value(1.0, 0.0, 1.0, 0.0, 10.0)) self.assertAlmostEqual(5.0, rescale_value(0.0, 0.0, 1.0, 5.0, 10.0)) self.assertAlmostEqual(6.25, rescale_value(0.25, 0.0, 1.0, 5.0, 10.0)) self.assertAlmostEqual(7.5, rescale_value(0.5, 0.0, 1.0, 5.0, 10.0)) self.assertAlmostEqual(8.75, rescale_value(0.75, 0.0, 1.0, 5.0, 10.0)) self.assertAlmostEqual(10.0, rescale_value(1.0, 0.0, 1.0, 5.0, 10.0)) self.assertAlmostEqual(-10.0, rescale_value(0.0, 0.0, 1.0, -10.0, 10.0)) self.assertAlmostEqual(-5.0, rescale_value(0.25, 0.0, 1.0, -10.0, 10.0)) self.assertAlmostEqual(0.0, rescale_value(0.5, 0.0, 1.0, -10.0, 10.0)) self.assertAlmostEqual(5.0, rescale_value(0.75, 0.0, 1.0, -10.0, 10.0)) self.assertAlmostEqual(10.0, rescale_value(1.0, 0.0, 1.0, -10.0, 10.0))