コード例 #1
0
        public PerlinNoise2D(int WidthPicture, int HeightPicture, float Persistence, float StartAmplitude, float StartFrequency, int NumberOfOctaves, InretpilationFunc IF, bool Smoothing, bool Random, bool Seamless)
        {
            m_Min             = m_Max = 0.0f;
            m_WidthPicture    = WidthPicture; m_HeightPicture = HeightPicture;
            m_Persistence     = Persistence;
            m_StartAmplitude  = StartAmplitude;
            m_StartFrequency  = StartFrequency;
            m_NumberOfOctaves = NumberOfOctaves;
            m_IF        = IF;
            m_Smoothing = Smoothing;
            m_Seamless  = Seamless;
            if (Random)
            {
                Random R = new Random();
                m_SeedX = R.Next(50000);
                m_SeedY = R.Next(50000);
            }
            else
            {
                m_SeedX = 0;
                m_SeedY = 0;
            }

            m_ResultNoise  = new float[m_WidthPicture, m_HeightPicture];
            m_OctavesNoise = new float[m_NumberOfOctaves, m_WidthPicture, m_HeightPicture];
        }
コード例 #2
0
        public Biomes[,] GenerateMap(float persistence, float amplitude, float frequency, bool smoothing, bool random, bool seamless, Interpolation interpolation)
        {
            int   WidthPicture = 320, HeightPicture = 160;
            float Persistence = persistence, StartAmplitude = amplitude, StartFrequency = frequency;

            InretpilationFunc IF = null;

            if (interpolation == Interpolation.None)
            {
                IF = None_Interpolate;
            }
            else if (interpolation == Interpolation.Linear)
            {
                IF = Linear_Interpolate;
            }
            else if (interpolation == Interpolation.Cosine)
            {
                IF = Cosine_Interpolate;
            }

            bool Smoothing = smoothing;
            bool Random    = random;

            PerlinNoise2D PN2D = new PerlinNoise2D(WidthPicture, HeightPicture, Persistence, StartAmplitude, StartFrequency, 4, IF, Smoothing, Random, seamless);

            PN2D.Generate();

            Tuple <int, int, int>[,] BMResult = new Tuple <int, int, int> [WidthPicture, HeightPicture];
            for (int x = 0; x < WidthPicture; ++x)
            {
                for (int y = 0; y < HeightPicture; ++y)
                {
                    int c;
                    c = (int)(255.0f * (PN2D.GetResultNoise(x, y) - PN2D.GetMin()) / (PN2D.GetMax() - PN2D.GetMin()));
                    BMResult[x, y] = new Tuple <int, int, int>(c, c, c);
                }
            }

            return(DrawMap(BMResult));
        }