Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Noise2D"/> class.
        /// <para>
        /// Performance is proportional to (largeFeatureScale/smallFeatureScale)^2, so if you need a wide range of feature sizes,
        /// it's better to add multiple "frequency bands" of noise together.
        /// </para>
        /// </summary>
        /// <param name="seed">A seed value to initialize the random number generator.</param>
        /// <param name="smallFeatureSize">A value proportional to the size of the smallest details created by the noise.</param>
        /// <param name="largeFeatureSize">A value proportional to the size of the largest details created by the noise.</param>
        public Noise2D(uint seed, double smallFeatureSize, double largeFeatureSize)
        {
            _seedHash = HashCalculator.FromSeed(seed);
            _scaleFactor = 1.0 / smallFeatureSize;
            _blurFactor = largeFeatureSize / smallFeatureSize;

            /* The blurred sampling is multiplied by this factor to make sure that the coefficients add up to the same value. */
            _blurNormalizationFactor = 1.0 / (_blurFactor * _blurFactor);
        }
Exemplo n.º 2
0
 private static double GetValue(HashCalculator hash)
 {
     /* Returns a deterministic "random" value in the range [-1, 1]. */
     return hash.GetHashCode() * (-1.0 / int.MinValue);
 }