pocketmine\level\generator\noise\Simplex::getNoise2D PHP Метод

getNoise2D() публичный Метод

public getNoise2D ( $x, $y )
    public function getNoise2D($x, $y)
    {
        $x += $this->offsetX;
        $y += $this->offsetY;
        // Skew the input space to determine which simplex cell we're in
        $s = ($x + $y) * self::$F2;
        // Hairy factor for 2D
        $i = (int) ($x + $s);
        $j = (int) ($y + $s);
        $t = ($i + $j) * self::$G2;
        // Unskew the cell origin back to (x,y) space
        $x0 = $x - ($i - $t);
        // The x,y distances from the cell origin
        $y0 = $y - ($j - $t);
        // For the 2D case, the simplex shape is an equilateral triangle.
        // Determine which simplex we are in.
        if ($x0 > $y0) {
            $i1 = 1;
            $j1 = 0;
        } else {
            $i1 = 0;
            $j1 = 1;
        }
        // upper triangle, YX order: (0,0)->(0,1)->(1,1)
        // A step of (1,0) in (i,j) means a step of (1-c,-c) in (x,y), and
        // a step of (0,1) in (i,j) means a step of (-c,1-c) in (x,y), where
        // c = (3-sqrt(3))/6
        $x1 = $x0 - $i1 + self::$G2;
        // Offsets for middle corner in (x,y) unskewed coords
        $y1 = $y0 - $j1 + self::$G2;
        $x2 = $x0 + self::$G22;
        // Offsets for last corner in (x,y) unskewed coords
        $y2 = $y0 + self::$G22;
        // Work out the hashed gradient indices of the three simplex corners
        $ii = $i & 255;
        $jj = $j & 255;
        $n = 0;
        // Calculate the contribution from the three corners
        $t0 = 0.5 - $x0 * $x0 - $y0 * $y0;
        if ($t0 > 0) {
            $gi0 = self::$grad3[$this->perm[$ii + $this->perm[$jj]] % 12];
            $n += $t0 * $t0 * $t0 * $t0 * ($gi0[0] * $x0 + $gi0[1] * $y0);
            // (x,y) of grad3 used for 2D gradient
        }
        $t1 = 0.5 - $x1 * $x1 - $y1 * $y1;
        if ($t1 > 0) {
            $gi1 = self::$grad3[$this->perm[$ii + $i1 + $this->perm[$jj + $j1]] % 12];
            $n += $t1 * $t1 * $t1 * $t1 * ($gi1[0] * $x1 + $gi1[1] * $y1);
        }
        $t2 = 0.5 - $x2 * $x2 - $y2 * $y2;
        if ($t2 > 0) {
            $gi2 = self::$grad3[$this->perm[$ii + 1 + $this->perm[$jj + 1]] % 12];
            $n += $t2 * $t2 * $t2 * $t2 * ($gi2[0] * $x2 + $gi2[1] * $y2);
        }
        // Add contributions from each corner to get the noise value.
        // The result is scaled to return values in the interval [-1,1].
        return 70.0 * $n;
    }