Example #1
0
 internal void createLandscape()
 {
     //Console.WriteLine(Config.SEED);
     PerlinNoiseGenerator.Seed = Config.SEED == 0 ? new Random().Next(Int32.MaxValue) : Config.SEED;
     //Console.WriteLine(PerlinNoiseGenerator.Seed);
     //Console.WriteLine(Int32.MaxValue);
     for (int i = 0; i < _height; i++)
     {
         for (int j = 0; j < _width; j++)
         {
             CellType type         = CellType.DEEP;
             double   perlineNoise = PerlinNoiseGenerator.Noise(i, j);
             if (perlineNoise > 80)
             {
                 type = CellType.LAND;
             }
             else
             if (perlineNoise > 20)
             {
                 type = CellType.SHALLOW;
             }
             field[i, j].Type = type;
         }
     }
     checkField();
 }
Example #2
0
        public static double Noise(int x, int y)
        {
            //returns -1 to 1
            //Console.WriteLine(PerlinNoiseGenerator.Seed);
            double total = 0.0;
            double freq = PerlinNoiseGenerator.Frequency, amp = PerlinNoiseGenerator.Amplitude;

            for (int i = 0; i < PerlinNoiseGenerator.Octaves; ++i)
            {
                total = total + PerlinNoiseGenerator.Smooth(x * freq, y * freq) * amp;
                freq *= 2;
                amp  *= PerlinNoiseGenerator.Persistence;
            }
            if (total < -2.4)
            {
                total = -2.4;
            }
            else if (total > 2.4)
            {
                total = 2.4;
            }
            //Console.WriteLine(total);
            return(total * 100);
        }