Пример #1
0
        static void perlin()
        {
            Console.WriteLine("Perlin:");

            noise.module.Module p = new noise.module.Perlin();
            var r = new Random();

            for (double x = 0.0; x < 20.0; x++)
            {
                for (double y = 0.0; y < 80.0; y++)
                {
                    var v = p.GetValue(x, y, r.NextDouble());
                    if (v < -0.5)
                    {
                        draw(0);
                    }
                    else if (v < 0.0)
                    {
                        draw(1);
                    }
                    else if (v < 0.5)
                    {
                        draw(2);
                    }
                    else
                    {
                        draw(3);
                    }
                }

                Console.WriteLine();
            }
        }
Пример #2
0
        static void generateTerrainExperiment()
        {
            const int SIZE   = 128;
            var       r      = new Random();
            var       output = new ImageGenerator(SIZE, SIZE);
            var       colors = new Color[SIZE, SIZE];
            var       billow = new noise.module.Billow();

            billow.Frequency    = 0.01;
            billow.NoiseQuality = NoiseQuality.QUALITY_BEST;
            billow.OctaveCount  = 30;
            // billow.Lacunarity = 0.5;
            // billow.Persistence = 0.1;


            var perlin = new noise.module.Perlin();

            perlin.NoiseQuality = NoiseQuality.QUALITY_FAST;
            perlin.Frequency    = 0.01;
            perlin.OctaveCount  = 12;

            var mul = new noise.module.Multiply();

            mul.InputB = billow;
            mul.InputA = perlin;

            var model = new noise.model.Plane(mul);

            for (int x = 0; x < SIZE; x++)
            {
                for (int y = 0; y < SIZE; y++)
                {
                    var v = model.GetValue(x, y);

                    if (v < -0.35)
                    {
                        colors[x, y] = Color.FromArgb(255, 25, 47, 81);
                    }
                    else if (v < -0.25)
                    {
                        colors[x, y] = Color.FromArgb(255, 36, 79, 147);
                    }
                    else if (v < -0.15)
                    {
                        colors[x, y] = Color.FromArgb(255, 47, 96, 175);
                    }
                    else if (v < -0.1)
                    {
                        colors[x, y] = Color.FromArgb(255, 30, 96, 204);
                    }
                    else if (v < 0.0)
                    {
                        colors[x, y] = Color.FromArgb(255, 42, 117, 237);
                    }
                    else if (v < 0.1)
                    {
                        colors[x, y] = Color.FromArgb(255, 232, 227, 201);
                    }
                    else if (v < 0.2)
                    {
                        colors[x, y] = Color.FromArgb(255, 130, 142, 102);
                    }
                    else if (v < 0.5)
                    {
                        colors[x, y] = Color.FromArgb(255, 89, 132, 71);
                    }
                    else if (v < 0.7)
                    {
                        colors[x, y] = Color.FromArgb(255, 55, 89, 41);
                    }
                    else if (v < 0.8)
                    {
                        colors[x, y] = Color.FromArgb(255, 68, 81, 62);
                    }
                    else if (v < 0.85)
                    {
                        colors[x, y] = Color.FromArgb(255, 90, 91, 89);
                    }
                    else if (v < 0.90)
                    {
                        colors[x, y] = Color.FromArgb(255, 57, 73, 48);
                    }
                    else if (v < 0.9995)
                    {
                        colors[x, y] = Color.FromArgb(255, 82, 89, 57);
                    }
                    else if (v < 1.0 - 0.000001)
                    {
                        colors[x, y] = Color.FromArgb(255, 112, 117, 85);
                    }
                    else if (v < 1.0 - 0.0000001)
                    {
                        colors[x, y] = Color.FromArgb(255, 122, 120, 99);
                    }
                    else if (v < 1.0 - 0.0000000000000000000000000000000001)
                    {
                        colors[x, y] = Color.FromArgb(255, 99, 97, 75);
                    }
                    else
                    {
                        colors[x, y] = Color.FromArgb(255, 120, 120, 120);
                    }
                }
            }
            output.Draw(colors);
            output.SaveToFile("terrain_experiment.bmp");
        }