Пример #1
0
        /// <inheritdoc/>
        protected override void ModifyTerrain(Point offset, TerrainBrush brush, byte[,] oldData, byte[,] newData)
        {
            #region Sanity checks
            if (oldData == null)
            {
                throw new ArgumentNullException(nameof(oldData));
            }
            if (newData == null)
            {
                throw new ArgumentNullException(nameof(newData));
            }
            #endregion

            var noise = new PerlinNoise {
                InitAmplitude = _amplitude, InitFrequency = _frequency
            };
            var heightMap = Terrain.HeightMap;

            // Iterate through intersection of [0,area.Size) and [-offset,heightMap-offset)
            for (int x = Math.Max(0, -offset.X); x < Math.Min(brush.Size, heightMap.Width - offset.X); x++)
            {
                for (int y = Math.Max(0, -offset.Y); y < Math.Min(brush.Size, heightMap.Height - offset.Y); y++)
                {
                    oldData[x, y] = heightMap[offset.X + x, offset.Y + y];

                    // Add noise and write back
                    newData[x, y] = heightMap[offset.X + x, offset.Y + y] =
                        (byte)(oldData[x, y] + (noise.Function2D(x, y) * brush.Factor(x, y))).Clamp(byte.MinValue, byte.MaxValue);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Generate texture.
        /// </summary>
        ///
        /// <param name="width">Texture's width.</param>
        /// <param name="height">Texture's height.</param>
        ///
        /// <returns>Two dimensional array of intensities.</returns>
        ///
        /// <remarks>Generates new texture of the specified size.</remarks>
        ///
        public override float[,] Generate(int width, int height)
        {
            var texture = new float[height, width];

            int r = Accord.Math.Random.Generator.Random.Next(5000);

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    float a = (float)Math.Sin(x + noise.Function2D(x + r, y + r));
                    float b = (float)Math.Sin(y + noise.Function2D(x + r, y + r));
                    texture[y, x] = Math.Max(0.0f, Math.Min(1.0f, (a + b) * 0.25f + 0.5f));
                }
            }

            return(texture);
        }
Пример #3
0
        /// <summary>
        /// Generate texture.
        /// </summary>
        ///
        /// <param name="width">Texture's width.</param>
        /// <param name="height">Texture's height.</param>
        ///
        /// <returns>Two dimensional array of intensities.</returns>
        ///
        /// <remarks>Generates new texture of the specified size.</remarks>
        ///
        public float[,] Generate(int width, int height)
        {
            float[,] texture = new float[height, width];

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    texture[y, x] =
                        Math.Max(0.0f, Math.Min(1.0f,
                                                (
                                                    (float)Math.Sin(x + noise.Function2D(x + r, y + r)) +
                                                    (float)Math.Sin(y + noise.Function2D(x + r, y + r))
                                                ) * 0.25f + 0.5f
                                                ));
                }
            }
            return(texture);
        }
Пример #4
0
 public float[,] Generate(int width, int height)
 {
     float[,] array = new float[height, width];
     for (int i = 0; i < height; i++)
     {
         for (int j = 0; j < width; j++)
         {
             array[i, j] = System.Math.Max(0f, System.Math.Min(1f, (float)noise.Function2D(j + r, i + r) * 0.5f + 0.5f));
         }
     }
     return(array);
 }
Пример #5
0
        /// <summary>
        /// Generate texture.
        /// </summary>
        ///
        /// <param name="width">Texture's width.</param>
        /// <param name="height">Texture's height.</param>
        ///
        /// <returns>Two dimensional array of intensities.</returns>
        ///
        /// <remarks>Generates new texture of the specified size.</remarks>
        ///
        public float[,] Generate(int width, int height)
        {
            float[,] texture = new float[height, width];

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    texture[y, x] =
                        Math.Min(1.0f,
                                 (float)Math.Abs(noise.Function2D(x + r, y + r))
                                 );
                }
            }
            return(texture);
        }
Пример #6
0
        public static ArrayMaterialMap CreatePerlinNoiseMap(PerlinNoise perlinNoise, int textureSize, Random random, MapType mapType)
        {
            int         displacementX = random.Next() / 32;
            int         displacementY = random.Next() / 32;
            List <Vec4> noise         = new List <Vec4>();

            for (int x = 0; x < textureSize; ++x)
            {
                for (int y = 0; y < textureSize; ++y)
                {
                    float val = Math.Max(0, Math.Min(1, 0.5f * ((float)perlinNoise.Function2D(x + displacementX, y + displacementY) + 1)));
                    noise.Add(new Vec4(val, val, val, 1));
                }
            }
            return(CreateRGBAMaterialFromVec4List(noise, textureSize, textureSize, mapType));
        }
Пример #7
0
        /// <summary>
        /// Generate texture.
        /// </summary>
        ///
        /// <param name="width">Texture's width.</param>
        /// <param name="height">Texture's height.</param>
        ///
        /// <returns>Two dimensional array of intensities.</returns>
        ///
        /// <remarks>Generates new texture of the specified size.</remarks>
        ///
        public override float[,] Generate(int width, int height)
        {
            var    texture = new float[height, width];
            double xFact   = xPeriod / width;
            double yFact   = yPeriod / height;

            int r = Accord.Math.Random.Generator.Random.Next(5000);

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    double a = (x * xFact + y * yFact + noise.Function2D(x + r, y + r));
                    texture[y, x] = Math.Min(1.0f, (float)Math.Abs(Math.Sin(a * Math.PI)));
                }
            }

            return(texture);
        }
Пример #8
0
        /// <summary>
        /// Generate texture.
        /// </summary>
        ///
        /// <param name="width">Texture's width.</param>
        /// <param name="height">Texture's height.</param>
        ///
        /// <returns>Two dimensional array of intensities.</returns>
        ///
        /// <remarks>Generates new texture of the specified size.</remarks>
        ///
        public float[,] Generate(int width, int height)
        {
            float[,] texture = new float[height, width];
            double xFact = xPeriod / width;
            double yFact = yPeriod / height;

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    texture[y, x] =
                        Math.Min(1.0f, (float)
                                 Math.Abs(Math.Sin(
                                              (x * xFact + y * yFact + noise.Function2D(x + r, y + r)) * Math.PI
                                              ))
                                 );
                }
            }
            return(texture);
        }
Пример #9
0
        /// <summary>
        /// Generate texture.
        /// </summary>
        ///
        /// <param name="width">Texture's width.</param>
        /// <param name="height">Texture's height.</param>
        ///
        /// <returns>Two dimensional array of intensities.</returns>
        ///
        /// <remarks>Generates new texture of the specified size.</remarks>
        ///
        public override float[,] Generate(int width, int height)
        {
            var texture = new float[height, width];
            int w2      = width / 2;
            int h2      = height / 2;

            int r = Accord.Math.Random.Generator.Random.Next(5000);

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    double xv = (double)(x - w2) / width;
                    double yv = (double)(y - h2) / height;

                    double a = (Math.Sqrt(xv * xv + yv * yv) + noise.Function2D(x + r, y + r));
                    texture[y, x] = Math.Min(1.0f, (float)Math.Abs(Math.Sin(a * Math.PI * 2 * rings)));
                }
            }

            return(texture);
        }
Пример #10
0
        override protected void Process()
        {
            var buckets = new double[60];
            var buffer  = new double[60];
            var stream  = new byte[buckets.Length + 2];

            var perlin = new PerlinNoise(OCTAVES, PERSISTENCE);

            while (Running)
            {
                for (int i = 0; i < buckets.Length; i++)
                {
                    buckets[i]  = perlin.Function2D(i * X_SCALE, time * T_SCALE);
                    buckets[i] += Math.Sqrt(2) / 2;
                    buckets[i] *= buckets[i] * buckets[i];
                    buckets[i]  = ((buckets[i] + 1) / 2) * 255;
                }

                Stream(buckets, stream);
                WaitForNextFrame();

                time += 1 / 60f;
            }
        }
Пример #11
0
        /// <summary>
        /// Generate texture.
        /// </summary>
        ///
        /// <param name="width">Texture's width.</param>
        /// <param name="height">Texture's height.</param>
        ///
        /// <returns>Two dimensional array of intensities.</returns>
        ///
        /// <remarks>Generates new texture of the specified size.</remarks>
        ///
        public float[,] Generate(int width, int height)
        {
            float[,] texture = new float[height, width];
            int w2 = width / 2;
            int h2 = height / 2;

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    double xv = (double)(x - w2) / width;
                    double yv = (double)(y - h2) / height;

                    texture[y, x] =
                        Math.Min(1.0f, (float)
                                 Math.Abs(Math.Sin(
                                              (Math.Sqrt(xv * xv + yv * yv) + noise.Function2D(x + r, y + r))
                                              * Math.PI * 2 * rings
                                              ))
                                 );
                }
            }
            return(texture);
        }
Пример #12
0
        public float[,] Generate(int width, int height)
        {
            float[,] array = new float[height, width];
            int num  = width / 2;
            int num2 = height / 2;

            for (int i = 0; i < height; i++)
            {
                for (int j = 0; j < width; j++)
                {
                    double num3 = (double)(j - num) / (double)width;
                    double num4 = (double)(i - num2) / (double)height;
                    array[i, j] = System.Math.Min(1f, (float)System.Math.Abs(System.Math.Sin((System.Math.Sqrt(num3 * num3 + num4 * num4) + noise.Function2D(j + r, i + r)) * System.Math.PI * 2.0 * rings)));
                }
            }
            return(array);
        }
Пример #13
0
        public float[,] Generate(int width, int height)
        {
            float[,] array = new float[height, width];
            double num  = xPeriod / (double)width;
            double num2 = yPeriod / (double)height;

            for (int i = 0; i < height; i++)
            {
                for (int j = 0; j < width; j++)
                {
                    array[i, j] = System.Math.Min(1f, (float)System.Math.Abs(System.Math.Sin(((double)j * num + (double)i * num2 + noise.Function2D(j + r, i + r)) * System.Math.PI)));
                }
            }
            return(array);
        }