コード例 #1
0
        public CloudyBrush(ExtBlock[] blocks, int[] counts, NoiseArgs n)
        {
            this.blocks     = blocks;
            this.counts     = counts;
            this.thresholds = new float[counts.Length];
            Random r = n.Seed == int.MinValue ? new Random() : new Random(n.Seed);

            noise = new ImprovedNoise(r);

            noise.Frequency   = n.Frequency;
            noise.Amplitude   = n.Amplitude;
            noise.Octaves     = n.Octaves;
            noise.Lacunarity  = n.Lacunarity;
            noise.Persistence = n.Persistence;
        }
コード例 #2
0
    public static float[,] GenerateNoiseMap(int mapWidth, int mapHeight, int seed, float scale, int octaves, float persistance, float lacunarity, Vector2 offset)
    {
        float[,] noiseMap = new float[mapWidth, mapHeight];

        System.Random prng          = new System.Random(seed);
        Vector2[]     octaveOffsets = new Vector2[octaves];
        for (int i = 0; i < octaves; i++)
        {
            float offsetX = prng.Next(-100000, 100000) + offset.x;
            float offsetY = prng.Next(-100000, 100000) + offset.y;
            octaveOffsets[i] = new Vector2(offsetX, offsetY);
        }

        if (scale <= 0)
        {
            scale = 0.0001f;
        }

        float maxNoiseHeight = float.MinValue;
        float minNoiseHeight = float.MaxValue;

        float halfWidth  = mapWidth / 2f;
        float halfHeight = mapHeight / 2f;


        for (int y = 0; y < mapHeight; y++)
        {
            for (int x = 0; x < mapWidth; x++)
            {
                float amplitude   = 1;
                float frequency   = 1;
                float noiseHeight = 0;

                for (int i = 0; i < octaves; i++)
                {
                    float sampleX = (x - halfWidth) / scale * frequency + octaveOffsets[i].x;
                    float sampleY = (y - halfHeight) / scale * frequency + octaveOffsets[i].y;

                    //float perlinValue = Mathf.PerlinNoise(sampleX, sampleY) * 2 - 1;

                    float perlinValue = ImprovedNoise.Noise(sampleX, sampleY) * 2 - 1;

                    noiseHeight += perlinValue * amplitude;

                    amplitude *= persistance;
                    frequency *= lacunarity;
                }

                if (noiseHeight > maxNoiseHeight)
                {
                    maxNoiseHeight = noiseHeight;
                }
                else if (noiseHeight < minNoiseHeight)
                {
                    minNoiseHeight = noiseHeight;
                }
                noiseMap[x, y] = noiseHeight;
            }
        }

        for (int y = 0; y < mapHeight; y++)
        {
            for (int x = 0; x < mapWidth; x++)
            {
                noiseMap[x, y] = Mathf.InverseLerp(minNoiseHeight, maxNoiseHeight, noiseMap[x, y]);
            }
        }

        return(noiseMap);
    }
コード例 #3
0
        public override Color At(PointType point)
        {
            var noise = ImprovedNoise.Noise(point);

            return(JitteredPattern.At(JitteredPattern.Transform.Inverse() * point * noise));
        }