
    OgH;                     ,   d Z dZddlmZmZmZ ddlmZ dZdZ	dZ
d ed	      d
z
  z  Zd	 ed	      z
  dz  ZdZdZdZ G d d      Z G d de      Zd Zd Z G d de      Z e       Zej,                  Zej0                  Z e       Zej0                  Zy)a?  Noise functions for procedural generation of content

Contains native code implementations of Perlin improved noise (with
fBm capabilities) and Perlin simplex noise. Also contains a fast
"fake noise" implementation in GLSL for execution in shaders.

Copyright (c) 2008, Casey Duncan (casey dot duncan at gmail dot com)
z1.2.1    )floorfmodsqrt)randint)   r   r   r   r   )r   r
   r   )r
   r
   r   )r   r   r   )r
   r   r   )r   r   r
   )r
   r   r
   )r   r   r   r   r
   r   )r   r   r
   r   r
   r
   r   r   r	   r   ) )r   r   r   r   )r   r   r   r
   )r   r   r
   r   )r   r   r
   r
   )r   r
   r   r   )r   r
   r   r
   )r   r
   r
   r   )r   r
   r
   r
   )r   r   r   r   )r   r   r   r
   )r   r   r
   r   )r   r   r
   r
   )r
   r   r   r   )r
   r   r   r
   )r
   r   r
   r   )r
   r   r
   r
   )r   r   r   r   )r   r   r   r
   )r   r
   r   r   )r   r
   r   r
   )r
   r   r   r   )r
   r   r   r
   )r
   r
   r   r   )r
   r
   r   r
   )r   r   r   r   )r   r   r
   r   )r   r
   r   r   )r   r
   r
   r   )r
   r   r   r   )r
   r   r
   r   )r
   r
   r   r   )r
   r
   r
   r   )@)r   r         )r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   )r   r   r   r   )r   r   r   r   r   )r   r   r   r   )r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   r   r   r   r   )r   r   r   r   r   )r   r   r   r   r   r   r   )r   r   r   r   )r   r   r   r   )r   r   r   r   )r   r   r   r   r   r   r   )r   r   r   r   r   )r   r   r   r   r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   )r   r   r   r   )r   r   r   r   r   )r   r   r   r   )r   r   r   r   r   r   r   )r   r   r   r   r   )r   r   r   r   )r   r   r   r         ?      @      ?g      @gUUUUUU?gUUUUUU?(            [   Z               _   `   5                  $   g      E         c   %         
                  x      K   r         >   ^            u   #          9      !   X         8   W         }            D      J      G         0         M            S   o      z   <               i   \   )   7   .      (      f      6   A      ?      r      P   I      L            Y                     t         V      d   m            r   @   4            |   {         &      v   ~      R   U            ;      /      :               *               w         r   ,         F         e         +      	         '      r   b   l   n   O   q               p   h         a         "                                 Q   3                  k   1                  j         T         s   y   2   -                        ]      r   C         H               N   B      =         c                   :    e Zd ZdZ ee      Zedz  ZddZddZ	y)	BaseNoisezNoise abstract base classr   Nc                     ||t        d      || j                  |       y|$t        |      dz  | _        t	        |      | _        yy)a  Initialize the noise generator. With no arguments, the default
        period and permutation table are used (256). The default permutation
        table generates the exact same noise pattern each time.

        An integer period can be specified, to generate a random permutation
        table with period elements. The period determines the (integer)
        interval that the noise repeats, which is useful for creating tiled
        textures.  period should be a power-of-two, though this is not
        enforced. Note that the speed of the noise algorithm is independent of
        the period size, though larger periods mean a larger table, which
        consume more memory.

        A permutation table consisting of an iterable sequence of whole
        numbers can be specified directly. This should have a power-of-two
        length. Typical permutation tables are a sequence of unique integers in
        the range [0,period) in random order, though other arrangements could
        prove useful, they will not be "pure" simplex noise. The largest
        element in the sequence must be no larger than period-1.

        period and permutation_table may not be specified together.
        Nz8Can specify either period or permutation_table, not bothr   )
ValueError	randomizetuplepermutationlenperiod)selfr  permutation_tables      V/var/www/html/public_html/myphp/venv/lib/python3.12/site-packages/ezdxf/math/perlin.py__init__zBaseNoise.__init__^   s_    , "3"?J  NN6"*$%67!;D/0DK +    c                     ||| _         t        t        | j                               }| j                   dz
  }t        |      D ]  }t        d|      }||   ||   c||<   ||<   ! t	        |      dz  | _        y)zRandomize the permutation table used by the noise functions. This
        makes them generate a different noise pattern for the same inputs.
        Nr   r   r   )r  listranger   r  r  )r  r  perm
perm_rightijs         r  r  zBaseNoise.randomize~   s~      DKE$++&'[[1_
d 	0A:&A#AwQDGT!W	0 !;?r  )NNN)
__name__
__module____qualname____doc__r  _permutationr  r  r  r   r  r  r  r  X   s$    #F"K1@+r  r  c                       e Zd ZdZd Zd Zy)SimplexNoisea  Perlin simplex noise generator

    Adapted from Stefan Gustavson's Java implementation described here:

    http://staffwww.itn.liu.se/~stegu/simplexnoise/simplexnoise.pdf

    To summarize:

    "In 2001, Ken Perlin presented 'simplex noise', a replacement for his classic
    noise algorithm.  Classic 'Perlin noise' won him an academy award and has
    become an ubiquitous procedural primitive for computer graphics over the
    years, but in hindsight it has quite a few limitations.  Ken Perlin himself
    designed simplex noise specifically to overcome those limitations, and he
    spent a lot of good thinking on it. Therefore, it is a better idea than his
    original algorithm. A few of the more prominent advantages are:

    * Simplex noise has a lower computational complexity and requires fewer
      multiplications.
    * Simplex noise scales to higher dimensions (4D, 5D and up) with much less
      computational cost, the complexity is O(N) for N dimensions instead of
      the O(2^N) of classic Noise.
    * Simplex noise has no noticeable directional artifacts.  Simplex noise has
      a well-defined and continuous gradient everywhere that can be computed
      quite cheaply.
    * Simplex noise is easy to implement in hardware."
    c                 D   ||z   t         z  }t        ||z         }t        ||z         }||z   t        z  }|||z
  z
  }|||z
  z
  }||kD  rd}	d}
nd}	d}
||	z
  t        z   }||
z
  t        z   }|t        dz  z   dz
  }|t        dz  z   dz
  }| j                  }t	        |      | j
                  z  }t	        |      | j
                  z  }||||   z      dz  }|||	z   |||
z      z      dz  }||dz   ||dz      z      dz  }d|dz  z
  |dz  z
  }|dkD  r!t        |   }|dz  |d   |z  |d   |z  z   z  }nd	}d|dz  z
  |dz  z
  }|dkD  r#t        |   }||dz  |d   |z  |d   |z  z   z  z  }d|dz  z
  |dz  z
  }|dkD  r#t        |   }||dz  |d   |z  |d   |z  z   z  z  }|d
z  S )z2D Perlin simplex noise.

        Return a floating point value from -1 to 1 for the given x, y coordinate.
        The same value is always returned for a given x, y pair unless the
        permutation table changes (see randomize above).
        r   r          @r   r   r   r   r           g     Q@)_F2r   _G2r  intr  _GRAD3)r  xysr!  r"  tx0y0i1j1x1y1x2y2r  iijjgi0gi1gi2ttgnoises                           r  noise2zSimplexNoise.noise2   s.    UcM!a%L!a%LUcM!a%[!a%[7BBBB"Ws]"Ws]sNS  	 #)^c! Vdkk!Vdkk!2R=!B&27T"r']*+b026DaL()B. 27]R1W$6sA!Gqtby1Q4"945EE27]R1W$6sAR1W!r	AaD2I 566E27]R1W$6sAR1W!r	AaD2I 566Et|r  c                 >   ||z   |z   t         z  }t        ||z         }t        ||z         }t        ||z         }||z   |z   t        z  }|||z
  z
  }	|||z
  z
  }
|||z
  z
  }|	|
k\  r1|
|k\  rd}d}d}d}d}d}nO|	|k\  rd}d}d}d}d}d}n=d}d}d}d}d}d}n0|
|k  rd}d}d}d}d}d}n|	|k  rd}d}d}d}d}d}nd}d}d}d}d}d}|	|z
  t        z   }|
|z
  t        z   }||z
  t        z   }|	|z
  dt        z  z   }|
|z
  dt        z  z   }||z
  dt        z  z   }|	dz
  dt        z  z   }|
dz
  dt        z  z   }|dz
  dt        z  z   }| j                  }t	        |      | j
                  z  }t	        |      | j
                  z  }t	        |      | j
                  z  }||||||   z      z      dz  }|||z   |||z   |||z      z      z      dz  } |||z   |||z   |||z      z      z      dz  }!||dz   ||dz   ||dz      z      z      dz  }"d}#d|	d	z  z
  |
d	z  z
  |d	z  z
  }$|$dkD  r*t        |   }%|$d
z  |%d   |	z  |%d   |
z  z   |%d	   |z  z   z  }#nd}#d|d	z  z
  |d	z  z
  |d	z  z
  }$|$dkD  r,t        |    }%|#|$d
z  |%d   |z  |%d   |z  z   |%d	   |z  z   z  z  }#d|d	z  z
  |d	z  z
  |d	z  z
  }$|$dkD  r,t        |!   }%|#|$d
z  |%d   |z  |%d   |z  z   |%d	   |z  z   z  z  }#d|d	z  z
  |d	z  z
  |d	z  z
  }$|$dkD  r,t        |"   }%|#|$d
z  |%d   |z  |%d   |z  z   |%d	   |z  z   z  z  }#|#dz  S )z3D Perlin simplex noise.

        Return a floating point value from -1 to 1 for the given x, y, z coordinate.
        The same value is always returned for a given x, y, z pair unless the
        permutation table changes (see randomize above).
        r   r   r-  r   r   r   r.  g333333?r   r   g      @@)_F3r   _G3r  r1  r  r2  )&r  r3  r4  zr5  r!  r"  kr6  r7  r8  z0r9  r:  k1i2j2k2r;  r<  z1r=  r>  z2x3y3z3r  r?  r@  kkrA  rB  rC  gi3rF  rD  rE  s&                                         r  noise3zSimplexNoise.noise3   ss    UQY#!a%L!a%L!a%LUQY#!a%[!a%[!a%[ 8RxrBwb "Ws]"Ws]"Ws]"WsSy "WsSy "WsSy #Xc	!#Xc	!#Xc	! Vdkk!Vdkk!Vdkk!2R$r(]++,r127T"r'DbM"9::;b@27T"r'DbM"9::;b@26Da$rAv,!67782= 27]R1W$rQw.6sA!Gqtby1Q4"94qtby@AEE27]R1W$rQw.6sAR1W!r	AaD2I 5!r	 ABBE27]R1W$rQw.6sAR1W!r	AaD2I 5!r	 ABBE27]R1W$rQw.6sAR1W!r	AaD2I 5!r	 ABBEt|r  N)r$  r%  r&  r'  rG  rY  r)  r  r  r+  r+     s    67rmr  r+  c                     || ||z
  z  z   S r#  r)  )r6  abs      r  lerpr]  Q  s    qAE{?r  c                 N    t         | dz     }||d   z  ||d   z  z   ||d   z  z   S )Nr   r   r   r   )r2  )hashr3  r4  rK  rE  s        r  grad3r`  U  s8    tbyAqt8a!A$hQqT))r  c                       e Zd ZdZddZy)TileableNoisezTileable implementation of Perlin "improved" noise. This
    is based on the reference implementation published here:

    http://mrl.nyu.edu/~perlin/noise/
    c                 d   t        t        t        |      |            }t        t        t        |      |            }t        t        t        |      |            }|dz   |z  }	|dz   |z  }
|dz   |z  }|r||z  }||z  }||z  }|	|z  }	|
|z  }
||z  }|t        |      z  }|t        |      z  }|t        |      z  }|dz  ||dz  dz
  z  dz   z  }|dz  ||dz  dz
  z  dz   z  }|dz  ||dz  dz
  z  dz   z  }| j                  }||   }|||z      }|||
z      }||	   }|||z      }|||
z      }t	        |t	        |t	        |t        |||z      |||      t        |||z      |dz
  ||            t	        |t        |||z      ||dz
  |      t        |||z      |dz
  |dz
  |                  t	        |t	        |t        |||z      |||dz
        t        |||z      |dz
  ||dz
              t	        |t        |||z      ||dz
  |dz
        t        |||z      |dz
  |dz
  |dz
                          S )zTileable 3D noise.

        repeat specifies the integer interval in each dimension
        when the noise pattern repeats.

        base allows a different texture to be generated for
        the same repeat interval.
        r   r   r1   r   r.   )r1  r   r   r  r]  r`  )r  r3  r4  rK  repeatbaser!  r"  rL  r?  r@  rW  fxfyfzr  AAAABBBABBs                         r  rY  zTileableNoise.noise3a  s    U1Xv&'U1Xv&'U1Xv&'!ev!ev!evIAIAIA$JB$JB$JB	U1X	U1X	U1X!VqAEBJ'",-!VqAEBJ'",-!VqAEBJ'",-G!a%[!b&\H!a%[!b&\$rAv,1a0$rAv,Aq!4
 $rAv,1q5!4$rAv,Aq1ua8 $rBw-Aq1u5$rBw-Q1q59
 $rBw-AE1q59$rBw-QAq1u=
 	
r  N)r.  )r$  r%  r&  r'  rY  r)  r  r  rb  rb  Z  s    B
r  rb  N)r'  __version__mathr   r   r   randomr   r2  _GRAD4_SIMPLEXr/  r0  rI  rJ  r(  r  r+  r]  r`  rb  _simplexrG  snoise2rY  snoise3	_tileabletnoise3r)  r  r  <module>ry     s     " " 
	
" 
T#Y_
T#Y#,1+ 1+hB9 BJ*
I
I I
X >
//
//O	


r  