Advertisement
Guest User

Untitled

a guest
Feb 16th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.77 KB | None | 0 0
  1. <?php
  2.  
  3. //код который долго считается
  4.     $i = 0;
  5.             $d0 = 1.0 / $noiseScale;
  6.             $k = -1;
  7.             $d1 = 0.0;
  8.             $d2 = 0.0;
  9.             $d3 = 0.0;
  10.             $d4 = 0.0;
  11.  
  12.             for ($l2 = 0; $l2 < $xSize; ++$l2) {
  13.                 $d5 = $xOffset + (float)$l2 * $xScale + $this->xCoord;
  14.                 $i3 = (int)$d5;
  15.  
  16.                 if ($d5 < (float)$i3) {
  17.                     --$i3;
  18.                 }
  19.  
  20.                 $j3 = $i3 & 255;
  21.                 $d5 = $d5 - (float)$i3;
  22.                 $d6 = $d5 * $d5 * $d5 * ($d5 * ($d5 * 6.0 - 15.0) + 10.0);
  23.  
  24.                 for ($k3 = 0; $k3 < $zSize; ++$k3) {
  25.                     $d7 = $zOffset + (float)$k3 * $zScale + $this->zCoord;
  26.                     $l3 = (int)$d7;
  27.  
  28.                     if ($d7 < (float)$l3) {
  29.                         --$l3;
  30.                     }
  31.  
  32.                     $i4 = $l3 & 255;
  33.                     $d7 = $d7 - (float)$l3;
  34.                     $d8 = $d7 * $d7 * $d7 * ($d7 * ($d7 * 6.0 - 15.0) + 10.0);
  35.  
  36.                     for ($j4 = 0; $j4 < $ySize; ++$j4) {
  37.                         $d9 = $yOffset + (float)$j4 * $yScale + $this->yCoord;
  38.                         $k4 = (int)$d9;
  39.  
  40.                         if ($d9 < (float)$k4) {
  41.                             --$k4;
  42.                         }
  43.  
  44.                         $l4 = $k4 & 255;
  45.                         $d9 = $d9 - (float)$k4;
  46.                         $d10 = $d9 * $d9 * $d9 * ($d9 * ($d9 * 6.0 - 15.0) + 10.0);
  47.  
  48.                         if ($j4 == 0 || $l4 != $k) {
  49.                             $k = $l4;
  50.                             $l = $this->permutations[$j3] + $l4;
  51.                             $i1 = $this->permutations[$l] + $i4;
  52.                             $j1 = $this->permutations[$l + 1] + $i4;
  53.                             $k1 = $this->permutations[$j3 + 1] + $l4;
  54.                             $l1 = $this->permutations[$k1] + $i4;
  55.                             $i2 = $this->permutations[$k1 + 1] + $i4;
  56.                             $d1 = $this->lerp($d6, $this->grad($this->permutations[$i1], $d5, $d9, $d7), $this->grad($this->permutations[$l1], $d5 - 1.0, $d9, $d7));
  57.                             $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));
  58.                             $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));
  59.                             $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));
  60.                         }
  61.  
  62.                         $d11 = $this->lerp($d10, $d1, $d2);
  63.                         $d12 = $this->lerp($d10, $d3, $d4);
  64.                         $d13 = $this->lerp($d8, $d11, $d12);
  65.                         $j7 = $i++;
  66.  
  67.                         $noiseArray[$j7] += ($d13 * $d0);
  68.                     }
  69.                 }
  70.             }
  71.  
  72.  
  73.  
  74.  
  75.  
  76. //functions
  77. /**
  78.      * @param $a
  79.      * @param $b
  80.      * @param $c
  81.      * @return float|int
  82.      */
  83.     function lerp($a, $b, $c)
  84.     {
  85.         return $b + $a * ($c - $b);
  86.     }
  87.  
  88.     /**
  89.      * @param $a
  90.      * @param $b
  91.      * @param $c
  92.      * @return float|int
  93.      */
  94.     function grad2($a, $b, $c)
  95.     {
  96.         $i = $a & 15;
  97.         return self::GRAD_2X[$i] * $b + self::GRAD_2Z[$i] * $c;
  98.     }
  99.  
  100.     /**
  101.      * @param $a
  102.      * @param $b
  103.      * @param $c
  104.      * @param $d
  105.      * @return float|int
  106.      */
  107.     function grad($a, $b, $c, $d)
  108.     {
  109.         $i = $a & 15;
  110.         return self::GRAD_X[$i] * $b + self::GRAD_Y[$i] * $c + self::GRAD_Z[$i] * $d;
  111.     }
  112. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement