Skip to content

Commit

Permalink
Improved logic of persistence
Browse files Browse the repository at this point in the history
  • Loading branch information
A1essandro committed May 16, 2016
1 parent cdfd0b7 commit 82b612f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion demo/visual.php
Expand Up @@ -6,7 +6,7 @@

$size = 8;

$gen->setPersistence(200);
$gen->setPersistence(1.8);
$gen->setSize($size);
$gen->setMapSeed(uniqid());
$map = $gen->generate();
Expand Down
4 changes: 3 additions & 1 deletion src/DiamondAndSquare.php
Expand Up @@ -242,7 +242,9 @@ private function diamond($x, $y, $size, $offset)
*/
private function getOffset($stepSize)
{
return (float)$stepSize / $this->size * mt_rand(-$this->getPersistence() / 2, $this->getPersistence() / 2);
$stepOffset = $stepSize / $this->size * mt_rand(-$this->size, $this->size);
$sign = $stepOffset < 0 ? -1 : 1;
return $sign * pow(abs($stepOffset), 1 / sqrt($this->getPersistence()));
}

/**
Expand Down

0 comments on commit 82b612f

Please sign in to comment.