public ChunkGeneratorSettings(int Seed, float NoiseScale, Overworld Overworld) { this.Overworld = Overworld; NoiseGenerator = new Perlin(Seed); this.NoiseScale = NoiseScale; CaveNoiseScale = NoiseScale * 10.0f; CaveSize = 0.03f; CaveFrequencies = new List <float>() { 0.5f, 0.7f, 0.9f, 1.0f }; CaveNoise = new FastRidgedMultifractal(Seed) { Frequency = 0.5f, Lacunarity = 0.5f, NoiseQuality = NoiseQuality.Standard, OctaveCount = 1, Seed = Seed }; CaveLevels = new List <int>(); var caveStep = 48 / Overworld.NumCaveLayers; for (var i = 0; i < Overworld.NumCaveLayers; ++i) { CaveLevels.Add(4 + (caveStep * i)); } }
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 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; } }