Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //код который долго считается
- $i = 0;
- $d0 = 1.0 / $noiseScale;
- $k = -1;
- $d1 = 0.0;
- $d2 = 0.0;
- $d3 = 0.0;
- $d4 = 0.0;
- for ($l2 = 0; $l2 < $xSize; ++$l2) {
- $d5 = $xOffset + (float)$l2 * $xScale + $this->xCoord;
- $i3 = (int)$d5;
- if ($d5 < (float)$i3) {
- --$i3;
- }
- $j3 = $i3 & 255;
- $d5 = $d5 - (float)$i3;
- $d6 = $d5 * $d5 * $d5 * ($d5 * ($d5 * 6.0 - 15.0) + 10.0);
- for ($k3 = 0; $k3 < $zSize; ++$k3) {
- $d7 = $zOffset + (float)$k3 * $zScale + $this->zCoord;
- $l3 = (int)$d7;
- if ($d7 < (float)$l3) {
- --$l3;
- }
- $i4 = $l3 & 255;
- $d7 = $d7 - (float)$l3;
- $d8 = $d7 * $d7 * $d7 * ($d7 * ($d7 * 6.0 - 15.0) + 10.0);
- for ($j4 = 0; $j4 < $ySize; ++$j4) {
- $d9 = $yOffset + (float)$j4 * $yScale + $this->yCoord;
- $k4 = (int)$d9;
- if ($d9 < (float)$k4) {
- --$k4;
- }
- $l4 = $k4 & 255;
- $d9 = $d9 - (float)$k4;
- $d10 = $d9 * $d9 * $d9 * ($d9 * ($d9 * 6.0 - 15.0) + 10.0);
- if ($j4 == 0 || $l4 != $k) {
- $k = $l4;
- $l = $this->permutations[$j3] + $l4;
- $i1 = $this->permutations[$l] + $i4;
- $j1 = $this->permutations[$l + 1] + $i4;
- $k1 = $this->permutations[$j3 + 1] + $l4;
- $l1 = $this->permutations[$k1] + $i4;
- $i2 = $this->permutations[$k1 + 1] + $i4;
- $d1 = $this->lerp($d6, $this->grad($this->permutations[$i1], $d5, $d9, $d7), $this->grad($this->permutations[$l1], $d5 - 1.0, $d9, $d7));
- $d2 = $this->lerp($d6, $this->grad($this->permutations[$j1], $d5, $d9 - 1.0, $d7), $this->grad($this->permutations[$i2], $d5 - 1.0, $d9 - 1.0, $d7));
- $d3 = $this->lerp($d6, $this->grad($this->permutations[$i1 + 1], $d5, $d9, $d7 - 1.0), $this->grad($this->permutations[$l1 + 1], $d5 - 1.0, $d9, $d7 - 1.0));
- $d4 = $this->lerp($d6, $this->grad($this->permutations[$j1 + 1], $d5, $d9 - 1.0, $d7 - 1.0), $this->grad($this->permutations[$i2 + 1], $d5 - 1.0, $d9 - 1.0, $d7 - 1.0));
- }
- $d11 = $this->lerp($d10, $d1, $d2);
- $d12 = $this->lerp($d10, $d3, $d4);
- $d13 = $this->lerp($d8, $d11, $d12);
- $j7 = $i++;
- $noiseArray[$j7] += ($d13 * $d0);
- }
- }
- }
- //functions
- /**
- * @param $a
- * @param $b
- * @param $c
- * @return float|int
- */
- function lerp($a, $b, $c)
- {
- return $b + $a * ($c - $b);
- }
- /**
- * @param $a
- * @param $b
- * @param $c
- * @return float|int
- */
- function grad2($a, $b, $c)
- {
- $i = $a & 15;
- return self::GRAD_2X[$i] * $b + self::GRAD_2Z[$i] * $c;
- }
- /**
- * @param $a
- * @param $b
- * @param $c
- * @param $d
- * @return float|int
- */
- function grad($a, $b, $c, $d)
- {
- $i = $a & 15;
- return self::GRAD_X[$i] * $b + self::GRAD_Y[$i] * $c + self::GRAD_Z[$i] * $d;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement