Better seed handling in perlin noise

Add seed, width and height to get param
Make map terrain more generic
This commit is contained in:
Tim
2023-06-05 02:11:44 +02:00
parent 542f1970f5
commit 5e522ea417
5 changed files with 46 additions and 32 deletions

View File

@ -9,7 +9,7 @@ class PerlinNoise
private float $seed;
private int $_default_size = 64;
public function __construct(float $seed = null)
public function __construct(?int $seed = null)
{
//Initialize the permutation array.
$this->p = [];
@ -36,10 +36,11 @@ class PerlinNoise
//And set the seed
if ($seed === null) {
$this->seed = time();
} else {
$this->seed = $seed;
$seed = time();
}
srand($seed);
$this->seed = rand(0, 1000000);
}
function noise($x, $y, $z, $size = NULL): float|int