Exemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            panel2.Enabled = false;

            NoiseQuality quality = NoiseQuality.Standard;

            if (radiolow.Checked)
                quality = NoiseQuality.Low;
            if (radiostandard.Checked)
                quality = NoiseQuality.Standard;
            if (radiohigh.Checked)
                quality = NoiseQuality.High;

            int seed = 0;
            try
            {
                seed = Convert.ToInt32(textBox1.Text);
            }
            catch
            {
                seed = 0;
                textBox1.Text = "0";
            }

            int octaves = 0;
            try
            {
                octaves = Convert.ToInt32(textBox2.Text);
            }
            catch
            {
                octaves = 6;
                textBox2.Text = "6";
            }
            if (octaves > 30) octaves = 30;

            double frequency = 0;
            try
            {
                frequency = Convert.ToDouble(textBox3.Text);
            }
            catch
            {
                frequency = 0.05;
                textBox3.Text = "0.05";
            }

            double lacunarity = 0;
            try
            {
                lacunarity = Convert.ToDouble(textBox4.Text);
            }
            catch
            {
                lacunarity = 2.0;
                textBox4.Text = "2.0";
            }

            double persistence = 0;
            try
            {
                persistence = Convert.ToDouble(textBox5.Text);
            }
            catch
            {
                persistence = 0.5;
                textBox5.Text = "0.5";
            }

            bool mapToSphere = false;

            IModule module;
            switch (listBox1.SelectedItem.ToString())
            {
                case "Slow Perlin":
                    module = new Perlin();
                    ((Perlin)module).Frequency = frequency;
                    ((Perlin)module).NoiseQuality = quality;
                    ((Perlin)module).Seed = seed;
                    ((Perlin)module).OctaveCount = octaves;
                    ((Perlin)module).Lacunarity = lacunarity;
                    ((Perlin)module).Persistence = persistence;
                    break;
                case "Fast Perlin":
                    module = new FastNoise();
                    ((FastNoise)module).Frequency = frequency;
                    ((FastNoise)module).NoiseQuality = quality;
                    ((FastNoise)module).Seed = seed;
                    ((FastNoise)module).OctaveCount = octaves;
                    ((FastNoise)module).Lacunarity = lacunarity;
                    ((FastNoise)module).Persistence = persistence;
                    break;
                case "Slow Billow":
                    module = new Billow();
                    ((Billow)module).Frequency = frequency;
                    ((Billow)module).NoiseQuality = quality;
                    ((Billow)module).Seed = seed;
                    ((Billow)module).OctaveCount = octaves;
                    ((Billow)module).Lacunarity = lacunarity;
                    ((Billow)module).Persistence = persistence;
                    break;
                case "Fast Billow":
                    module = new FastBillow();
                    ((FastBillow)module).Frequency = frequency;
                    ((FastBillow)module).NoiseQuality = quality;
                    ((FastBillow)module).Seed = seed;
                    ((FastBillow)module).OctaveCount = octaves;
                    ((FastBillow)module).Lacunarity = lacunarity;
                    ((FastBillow)module).Persistence = persistence;
                    break;
                case "Slow Ridged Multifractal":
                    module = new RidgedMultifractal();
                    ((RidgedMultifractal)module).Frequency = frequency;
                    ((RidgedMultifractal)module).NoiseQuality = quality;
                    ((RidgedMultifractal)module).Seed = seed;
                    ((RidgedMultifractal)module).OctaveCount = octaves;
                    ((RidgedMultifractal)module).Lacunarity = lacunarity;
                    break;
                case "Fast Ridged Multifractal":
                    module = new FastRidgedMultifractal();
                    ((FastRidgedMultifractal)module).Frequency = frequency;
                    ((FastRidgedMultifractal)module).NoiseQuality = quality;
                    ((FastRidgedMultifractal)module).Seed = seed;
                    ((FastRidgedMultifractal)module).OctaveCount = octaves;
                    ((FastRidgedMultifractal)module).Lacunarity = lacunarity;
                    break;
                case "Slow Combined":
                    Billow billow = new Billow();
                    billow.Frequency = frequency;
                    billow.NoiseQuality = quality;
                    billow.Seed = seed;
                    billow.OctaveCount = octaves;
                    billow.Lacunarity = lacunarity;
                    billow.Persistence = persistence;

                    ScaleBiasOutput scaledBillow = new ScaleBiasOutput(billow);
                    scaledBillow.Bias = -0.75;
                    scaledBillow.Scale = 0.125;

                    RidgedMultifractal ridged = new RidgedMultifractal();
                    ridged.Frequency = frequency/2.0;
                    ridged.NoiseQuality = quality;
                    ridged.Seed = seed;
                    ridged.OctaveCount = octaves;
                    ridged.Lacunarity = lacunarity;

                    Perlin perlin = new Perlin();
                    perlin.Frequency = frequency/10.0;
                    perlin.NoiseQuality = quality;
                    perlin.Seed = seed;
                    perlin.OctaveCount = octaves;
                    perlin.Lacunarity = lacunarity;
                    perlin.Persistence = persistence;

                    Select selector = new Select(perlin, ridged, scaledBillow);
                    selector.SetBounds(0, 1000);
                    selector.EdgeFalloff = 0.5;

                    module = selector;
                    break;
                case "Fast Combined":
                    FastBillow fastbillow = new FastBillow();
                    fastbillow.Frequency = frequency;
                    fastbillow.NoiseQuality = quality;
                    fastbillow.Seed = seed;
                    fastbillow.OctaveCount = octaves;
                    fastbillow.Lacunarity = lacunarity;
                    fastbillow.Persistence = persistence;

                    ScaleBiasOutput fastscaledBillow = new ScaleBiasOutput(fastbillow);
                    fastscaledBillow.Bias = -0.75;
                    fastscaledBillow.Scale = 0.125;

                    FastRidgedMultifractal fastridged = new FastRidgedMultifractal();
                    fastridged.Frequency = frequency/2.0;
                    fastridged.NoiseQuality = quality;
                    fastridged.Seed = seed;
                    fastridged.OctaveCount = octaves;
                    fastridged.Lacunarity = lacunarity;

                    FastNoise fastperlin = new FastNoise();
                    fastperlin.Frequency = frequency/10.0;
                    fastperlin.NoiseQuality = quality;
                    fastperlin.Seed = seed;
                    fastperlin.OctaveCount = octaves;
                    fastperlin.Lacunarity = lacunarity;
                    fastperlin.Persistence = persistence;

                    Select fastselector = new Select(fastperlin, fastridged, fastscaledBillow);
                    fastselector.SetBounds(0, 1000);
                    fastselector.EdgeFalloff = 0.5;

                    module = fastselector;
                    break;
                case "Voronoi":
                    module = new Voronoi();
                    ((Voronoi)module).Frequency = frequency;
                    break;
                case "Slow Planet":
                    mapToSphere = true;

                    Perlin slowPlanetContinents = new Perlin();
                    slowPlanetContinents.Frequency = 1.5;

                    Billow slowPlanetLowlands = new Billow();
                    slowPlanetLowlands.Frequency = 4;
                    LibNoise.Modifiers.ScaleBiasOutput slowPlanetLowlandsScaled = new ScaleBiasOutput(slowPlanetLowlands);
                    slowPlanetLowlandsScaled.Scale = 0.2;
                    slowPlanetLowlandsScaled.Bias = 0.5;

                    RidgedMultifractal slowPlanetMountainsBase = new RidgedMultifractal();
                    slowPlanetMountainsBase.Frequency = 4;

                    ScaleBiasOutput slowPlanetMountainsScaled = new ScaleBiasOutput(slowPlanetMountainsBase);
                    slowPlanetMountainsScaled.Scale = 0.4;
                    slowPlanetMountainsScaled.Bias = 0.85;

                    FastTurbulence slowPlanetMountains = new FastTurbulence(slowPlanetMountainsScaled);
                    slowPlanetMountains.Power = 0.1;
                    slowPlanetMountains.Frequency = 50;

                    Perlin slowPlanetLandFilter = new Perlin();
                    slowPlanetLandFilter.Frequency = 6;

                    Select slowPlanetLand = new Select(slowPlanetLandFilter, slowPlanetLowlandsScaled, slowPlanetMountains);
                    slowPlanetLand.SetBounds(0, 1000);
                    slowPlanetLand.EdgeFalloff = 0.5;

                    Billow slowPlanetOceanBase = new Billow();
                    slowPlanetOceanBase.Frequency = 15;
                    ScaleOutput slowPlanetOcean = new ScaleOutput(slowPlanetOceanBase, 0.1);

                    Select slowPlanetFinal = new Select(slowPlanetContinents, slowPlanetOcean, slowPlanetLand);
                    slowPlanetFinal.SetBounds(0, 1000);
                    slowPlanetFinal.EdgeFalloff = 0.5;

                    module = slowPlanetFinal;
                    break;
                case "Fast Planet":
                    mapToSphere = true;

                    FastNoise fastPlanetContinents = new FastNoise(seed);
                    fastPlanetContinents.Frequency = 1.5;

                    FastBillow fastPlanetLowlands = new FastBillow();
                    fastPlanetLowlands.Frequency = 4;
                    LibNoise.Modifiers.ScaleBiasOutput fastPlanetLowlandsScaled = new ScaleBiasOutput(fastPlanetLowlands);
                    fastPlanetLowlandsScaled.Scale = 0.2;
                    fastPlanetLowlandsScaled.Bias = 0.5;

                    FastRidgedMultifractal fastPlanetMountainsBase = new FastRidgedMultifractal(seed);
                    fastPlanetMountainsBase.Frequency = 4;

                    ScaleBiasOutput fastPlanetMountainsScaled = new ScaleBiasOutput(fastPlanetMountainsBase);
                    fastPlanetMountainsScaled.Scale = 0.4;
                    fastPlanetMountainsScaled.Bias = 0.85;

                    FastTurbulence fastPlanetMountains = new FastTurbulence(fastPlanetMountainsScaled);
                    fastPlanetMountains.Power = 0.1;
                    fastPlanetMountains.Frequency = 50;

                    FastNoise fastPlanetLandFilter = new FastNoise(seed+1);
                    fastPlanetLandFilter.Frequency = 6;

                    Select fastPlanetLand = new Select(fastPlanetLandFilter, fastPlanetLowlandsScaled, fastPlanetMountains);
                    fastPlanetLand.SetBounds(0, 1000);
                    fastPlanetLand.EdgeFalloff = 0.5;

                    FastBillow fastPlanetOceanBase = new FastBillow(seed);
                    fastPlanetOceanBase.Frequency = 15;
                    ScaleOutput fastPlanetOcean = new ScaleOutput(fastPlanetOceanBase, 0.1);

                    Select fastPlanetFinal = new Select(fastPlanetContinents, fastPlanetOcean, fastPlanetLand);
                    fastPlanetFinal.SetBounds(0, 1000);
                    fastPlanetFinal.EdgeFalloff = 0.5;

                    module = fastPlanetFinal;
                    break;
                default:
                    module = new Constant(1.0);
                    break;
            }

            System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch();
            stopWatch.Start();

            LibNoise.Models.Sphere sphere = new LibNoise.Models.Sphere(module);

            for (int x = 0; x < pictureBox1.ClientSize.Width - 1; x++)
                for (int y = 0; y < pictureBox1.ClientSize.Height - 1; y++)
                {
                    double value;
                    if(mapToSphere)
                    {
                        int offsetX = -(x-512);
                        int offsetY = -(y-512);
                        double longitude = offsetY/5.6888888888;
                        if(longitude > 90.0) longitude = 90.0;
                        if(longitude < -90.0) longitude = -90.0;
                        double latitude = offsetX/2.844444444;
                        if(latitude > 180.0) latitude = 180.0;
                        if(latitude < -190.0) latitude = -180.0;
                        value = sphere.GetValue(longitude, latitude);
                    }
                    else
                        value = (module.GetValue(x, y, 10) + 1) / 2.0;
                    if (mapToSphere)
                    {
                        if (value < 0) value = 0;
                        if (value > 1.0) value = 1.0;
                        int index = (int)(value * earthLookupTable.Length);
                        if (index >= earthLookupTable.Length) index = earthLookupTable.Length - 1;
                        colors[x, y] = earthLookupTable[index];
                    }
                    else
                    {
                        if (value < 0) value = 0;
                        if (value > 1.0) value = 1.0;
                        byte intensity = (byte)(value * 255.0);
                        colors[x, y] = Color.FromArgb(255, intensity, intensity, intensity);
                    }
                }

            stopWatch.Stop();
            label2.Text = "Generation time for a 1024x1024 image, not including rendering: " + stopWatch.Elapsed.TotalMilliseconds + " ms";

            for (int x = 0; x < pictureBox1.ClientSize.Width - 1; x++)
                for (int y = 0; y < pictureBox1.ClientSize.Height - 1; y++)
                    bitmap.SetPixel(x, y, colors[x, y]);

            pictureBox1.Image = bitmap;

            panel2.Enabled = true;
        }
        public void Init()
        {
            int Seed = m.GetSeed();

            BiomeBase.Frequency = (0.2);
            BiomeBase.Seed = (Seed - 1);
            BiomeSelect = new ScaleBiasOutput(BiomeBase);
            BiomeSelect.Scale = (2.5);
            BiomeSelect.Bias = (2.5);
            mountainTerrainBase.Seed = (Seed + 1);
            mountainTerrain = new ScaleBiasOutput(mountainTerrainBase);
            mountainTerrain.Scale = (0.5);
            mountainTerrain.Bias = (0.5);
            jaggieEdges = new Select(jaggieControl, terrainType, plain);
            plain.Value = (0.5);
            jaggieEdges.SetBounds(0.5, 1.0);
            jaggieEdges.EdgeFalloff = (0.11);
            jaggieControl.Seed = (Seed + 20);
            baseFlatTerrain.Seed = (Seed);
            baseFlatTerrain.Frequency = (0.2);
            flatTerrain = new ScaleBiasOutput(baseFlatTerrain);
            flatTerrain.Scale = (0.125);
            flatTerrain.Bias = (0.07);
            baseWater.Seed = (Seed - 1);
            water = new ScaleBiasOutput(baseWater);
            water.Scale = (0.3);
            water.Bias = (-0.5);
            terrainType.Seed = (Seed + 2);
            terrainType.Frequency = (0.5);
            terrainType.Persistence = (0.25);
            terrainType2.Seed = (Seed + 7);
            terrainType2.Frequency = (0.5);
            terrainType2.Persistence = (0.25);
            waterTerrain = new Select(terrainType2, water, flatTerrain);
            waterTerrain.EdgeFalloff = (0.1);
            waterTerrain.SetBounds(-0.5, 1.0);
            secondTerrain = new Select(terrainType, mountainTerrain, waterTerrain);
            secondTerrain.EdgeFalloff = (0.3);
            secondTerrain.SetBounds(-0.5, 1.0);
            finalTerrain = new Select(jaggieEdges, secondTerrain, waterTerrain);
            finalTerrain.EdgeFalloff = (0.2);
            finalTerrain.SetBounds(-0.3, 1.0);
            flowers.Seed = (Seed + 10);
            flowers.Frequency = (3);

            // Set up us the Perlin-noise module.
            caveNoise.Seed = (Seed + 22);
            caveNoise.Frequency = (1.0 / cavessize);
            caveNoise.OctaveCount = (4);
        }
Exemplo n.º 3
0
 public AdapterScaleBias()
     : base()
 {
     noise = new ScaleBiasOutput(null);
 }
Exemplo n.º 4
0
		public static IModule GetEarthModule(int seed, int resolution)
		{
			if(true) {
				double factor = 1.0/resolution;
				FastNoise Continentsprescale = new FastNoise(seed);
				Continentsprescale.Frequency = 1*factor;

				ScaleBiasOutput Continents = new ScaleBiasOutput(Continentsprescale);
				Continents.Scale = .65;
				Continents.Bias = .35;

				FastBillow LowLands = new FastBillow(seed);
				LowLands.Frequency = .4*factor;
				ScaleBiasOutput LowLandsScaled = new ScaleBiasOutput(LowLands);
				LowLandsScaled.Scale = 0.1;
				LowLandsScaled.Bias = 0.5;

				FastRidgedMultifractal Mountains = new FastRidgedMultifractal(seed);
				Mountains.Frequency = 1*factor;
				Mountains.Lacunarity = 2;
				Mountains.OctaveCount = 16;

				ScaleBiasOutput MountainsScaledpreturb = new ScaleBiasOutput(Mountains);
				MountainsScaledpreturb.Scale = 0.4;
				MountainsScaledpreturb.Bias = 0.85;
				//FastTurbulence MountainsFinal = new FastTurbulence(MountainsScaled)
				FastTurbulence MountainsScaled = new FastTurbulence(MountainsScaledpreturb);
				MountainsScaled.Frequency = 50*factor;
				MountainsScaled.Power = 0.1;
				FastNoise LandFilterprescale = new FastNoise(seed+1);
				LandFilterprescale.Frequency = .6*factor;
				ScaleBiasOutput LandFilter = new ScaleBiasOutput(LandFilterprescale);
				LandFilter.Bias = 0;

				Select LandFinal1 = new Select(LandFilter, LowLandsScaled, MountainsScaled);
				LandFinal1.SetBounds(0, 100);
				LandFinal1.EdgeFalloff = (.5);
				//AbsoluteOutput LandFinal = new AbsoluteOutput(LandFinal1);
				var LandFinal = new ScaleBiasOutput(LandFinal1);

				FastBillow Ocean = new FastBillow(seed);
				Ocean.Frequency = .5*factor;
				ScaleBiasOutput OceanScaled = new ScaleBiasOutput(Ocean);
				OceanScaled.Scale = 0.1;
				OceanScaled.Bias = 0.1;

				Select Final = new Select(Continents, new Constant(0), new Constant(1));
				Final.SetBounds(0, 100);
				//Final.EdgeFalloff=(0.5);
				Select Finalx = new Select(Continents, LandFinal, OceanScaled);
				Finalx.SetBounds(0, 100);
				//Finalx.EdgeFalloff=(0.5);
				Select Final2 = new Select(LandFinal1, new Constant(.5), new Constant(.3));
				Final2.SetBounds(0, 100);
				//Final2.EdgeFalloff = .5;
				Select Final3 = new Select(Finalx, Final, Final2);
				Final3.SetBounds(0, 100);
				var outpoot = /*new AbsoluteOutput*/new VoronoiRelaxed() { Frequency = 4*factor,RelaxationFactor=1 ,Seed=seed};	
				var fin = new Select(Continentsprescale, new Constant(-1), outpoot);
				fin.SetBounds(0, 100);		//Final3.EdgeFalloff = .5;
				//fin.EdgeFalloff=0.05;
				var zones = /*new VoronoiLarge(new VoronoiLarge(*/new VoronoiLarge(fin) { Frequency = factor*20, RelaxationFactor = .75 };//){Frequency=factor*8,RelaxationFactor=0}){Frequency=factor*16,RelaxationFactor=0};
				var fin2 = zones;
				return fin2;
			}
			else {
				double factor = 1.0/resolution;
				FastNoise fastPlanetContinents = new FastNoise(seed);
				fastPlanetContinents.Frequency = 1.5*factor;

				FastBillow fastPlanetLowlands = new FastBillow();
				fastPlanetLowlands.Frequency = 4*factor;
				LibNoise.Modifiers.ScaleBiasOutput fastPlanetLowlandsScaled = new ScaleBiasOutput(fastPlanetLowlands);
				fastPlanetLowlandsScaled.Scale = 0.2;
				fastPlanetLowlandsScaled.Bias = 0.5;

				FastRidgedMultifractal fastPlanetMountainsBase = new FastRidgedMultifractal(seed);
				fastPlanetMountainsBase.Frequency = 4*factor;

				ScaleBiasOutput fastPlanetMountainsScaled = new ScaleBiasOutput(fastPlanetMountainsBase);
				fastPlanetMountainsScaled.Scale = 0.4;
				fastPlanetMountainsScaled.Bias = 0.85;

				FastTurbulence fastPlanetMountains = new FastTurbulence(fastPlanetMountainsScaled);
				fastPlanetMountains.Power = 0.1;
				fastPlanetMountains.Frequency = 50*factor;

				FastNoise fastPlanetLandFilter = new FastNoise(seed+1);
				fastPlanetLandFilter.Frequency = 6*factor;

				Select fastPlanetLand = new Select(fastPlanetLandFilter, fastPlanetLowlandsScaled, fastPlanetMountains);
				fastPlanetLand.SetBounds(0, 1000);
				fastPlanetLand.EdgeFalloff = 0.5;

				FastBillow fastPlanetOceanBase = new FastBillow(seed);
				fastPlanetOceanBase.Frequency = 15*factor;
				ScaleOutput fastPlanetOcean = new ScaleOutput(fastPlanetOceanBase, 0.1);

				Select fastPlanetFinal = new Select(fastPlanetContinents, fastPlanetOcean, fastPlanetLand);
				fastPlanetFinal.SetBounds(0, 1000);
				fastPlanetFinal.EdgeFalloff = 0.5;
				return fastPlanetFinal;
			}
		}
Exemplo n.º 5
0
        private static void Run(int octaves, double persistence, double frequency, double lacunarity)
        {
            string fileName = string.Format("O{3}_P{0:N3}_F{1:N3}.png", persistence, frequency, lacunarity, octaves);
              Billow billow = new Billow();
              billow.Frequency = frequency;
              billow.NoiseQuality = NoiseQuality.High;
              billow.Seed = 0;
              billow.OctaveCount = octaves;
              billow.Lacunarity = lacunarity;
              billow.Persistence = persistence;

              ScaleBiasOutput scaledBillow = new ScaleBiasOutput(billow);
              scaledBillow.Bias = -0.75;
              scaledBillow.Scale = 0.125;

              RidgedMultifractal ridged = new RidgedMultifractal();
              ridged.Frequency = frequency;
              ridged.NoiseQuality = NoiseQuality.High;
              ridged.Seed = 0;
              ridged.OctaveCount = octaves;
              ridged.Lacunarity = lacunarity;

              Perlin perlin = new Perlin();
              perlin.Frequency = frequency;
              perlin.NoiseQuality = NoiseQuality.High;
              perlin.Seed = 0;
              perlin.OctaveCount = octaves;
              perlin.Lacunarity = lacunarity;
              perlin.Persistence = persistence;

              Select selector = new Select(perlin, ridged, scaledBillow);
              selector.SetBounds(0, 1000);
              selector.EdgeFalloff = 0.5;
              IModule module = selector;
              //RidgedMultifractal module = new RidgedMultifractal();
              //((RidgedMultifractal)module).Frequency = frequency;
              //((RidgedMultifractal)module).NoiseQuality = NoiseQuality.High;
              //((RidgedMultifractal)module).Seed = 0;
              //((RidgedMultifractal)module).OctaveCount = octaves;
              //((RidgedMultifractal)module).Lacunarity = lacunarity;
              //((RidgedMultifractal)module).Persistence = persistence;
              Pen blackPen = new Pen(Color.Black, 1);
              Font arialFont = new Font("Arial", 8);

              double min = double.MaxValue;
              double max = double.MinValue;
              double avg = 0;

              using (Bitmap b = new Bitmap(300, 2500))
              {
            using (Graphics g = Graphics.FromImage(b))
            {
              g.Clear(Color.White);
              for (int i = 0; i < 5000; i++)
              {
            var value = module.GetValue(i, 0, 0);
            avg += value;
            if (value < min)
            {
              min = value;
            }
            if (value > max)
            {
              max = value;
            }
            g.DrawRectangle(blackPen, 150 + (int)System.Math.Round(value * 100), i / 2, 1, 1);
              }
              avg /= 5000;
              g.DrawString(string.Format("Samples: {0:N3}\r\nMin: {1:N3}\r\nMax: {2:N3}\r\nAverage: {3:N3}", 5000, min, max, avg), arialFont, Brushes.DarkBlue, 5f, 60f);
              g.DrawString(string.Format("Frequency: {0:N3}\r\nPersistence: {1:N3}\r\nLacunarity: {2:N3}\r\nOctaves: {3:N3}", frequency, persistence, lacunarity, octaves), arialFont, Brushes.DarkGreen, 5f, 5f);
            }
            b.Save(@"Combined\" + fileName, ImageFormat.Png);
              }
        }