public INoise GetLandFormFct() { //REM //The various parameters value here are scaled for a gradient being feed by 0 to 1 input value. //When this gradient is configured to recevied other value range then some parameters needs to be rescaled //That's the reason for using this _groundGradientTyped.AdjustY value //This way no matter the the Gradient Range, the values impacting it will be rescaled. //Create the Lowland base fractal with range from 0 to 1 values INoise montain_shape_fractal = new FractalFbm(new Simplex(_seed), 4, 3.5, enuBaseNoiseRange.ZeroToOne); INoise montain_shape_Ajusted = new ScaleOffset(montain_shape_fractal, 0.9, -0.02); //Rescale + offset the output result ==> Wil modify the Scope of output range value //Enforce gradient to have a solid underground INoise _groundGradientAjusted = new Bias(_groundGradient, 0.55); INoise adjustedGradient = new ScaleOffset(_groundGradientAjusted, 1.4, 0); Combiner noiseCombiner = new Combiner(Combiner.CombinerType.Add); noiseCombiner.Noises.Add(montain_shape_Ajusted); noiseCombiner.Noises.Add(adjustedGradient); INoise rescaledCombinedNoise = new ScaleOffset(noiseCombiner, 0.45, 0); return(rescaledCombinedNoise); }
/*private float Noise(IModule2D noise, float x) * { * return noise.GetValue(x, 0) / 2f + 0.5f; * }*/ /*public float Turbulence(int y, int x) * { * return (float)(this.Gradient(y, x) + this.random.NextDouble() * 0.25d - 0.25d); * }*/ /*private class Gradient : IModule2D * { * public Gradient() * { * } * * public float GetValue(float x, float y) * { * return y * 2 - 1f; * } * }*/ public IEnumerable <Point> Generate() { /*var fractal = new MultiFractal(); * fractal.OctaveCount = 6f; * fractal.Frequency = 2f; * fractal.Primitive2D = new Gradient();*/ var gradient = new Gradient(0, 0, 0, 1); var fractal = new Fractal(FractalType.FBM, BasisTypes.GRADIENT, InterpTypes.QUINTIC, octaves: 6, frequency: 2d, seed: null); var scale = new ScaleOffset(0.5d, 0, fractal); var perturb = new TranslatedDomain(gradient, null, scale); var select = new Select(perturb, 0, 1, 0.5d, null); for (var y = 0; y < this.map.Height; y++) { for (var x = 0; x < this.map.Width; x++) { var value = select.Get((double)x / (this.map.Width / 2), (double)y / (this.map.Height / 2)); if (value > 0.5) { this.map[y, x].Block = new Material(MaterialType.Dirt); } } } yield break; }
public INoise GetLandFormFct() { //REM //The various parameters value here are scaled for a gradient being feed by 0 to 1 input value. //When this gradient is configured to recevied other value range then some parameters needs to be rescaled //That's the reason for using this _groundGradientTyped.AdjustY value //This way no matter the the Gradient Range, the values impacting it will be rescaled. //Create the Lowland base fractal with range from 0 to 1 values INoise river_shape_fractal = new FractalRidgedMulti(new Simplex(_seed), 1, 2, enuBaseNoiseRange.ZeroToOne); //Rescale + offset the output result ==> Wil modify the Scope of output range value INoise river_shape_scale = new ScaleOffset(river_shape_fractal, 0.30, 0.01); //Remove Y value from impacting the result (Fixed to 0), the value output range will not be changed, but the influence of the Y will be removed //Force the Fractal to be used as 2D Noise, I don't need to 3th dimension INoise river_y_scale = new NoiseAccess(river_shape_fractal, NoiseAccess.enuDimUsage.Noise2D, true); INoise turb = new ScaleOffset(river_y_scale, 0.03, 0); INoise river_selected = new Select(0, turb, river_y_scale, 0.7); //Last param define the width of the river //Offset the ground_gradient ( = create turbulance) to the Y scale of the gradient. input value INoise _groundGradient_biased = new Bias(_groundGradient, 0.45); INoise river = new Turbulence(_groundGradient_biased, 0, river_selected); return(river); }
public static ModuleBase Caves() { Fractal cave_shape = new Fractal(FractalType.RIDGEDMULTI, BasisTypes.GRADIENT, InterpTypes.QUINTIC, 2, 4, (uint)UnityEngine.Random.Range(0, 10000)); Select cave_select = new Select(cave_shape, 1, 0, 0.4, 0); Fractal cave_perturb_fractal = new Fractal(FractalType.FBM, BasisTypes.GRADIENT, InterpTypes.QUINTIC, 6, 3, null); ScaleOffset cave_perturb_scale = new ScaleOffset(0.25, 0, cave_perturb_fractal); TranslatedDomain cave_perturb = new TranslatedDomain(cave_select, cave_perturb_scale, null); Select selection = new Select(cave_perturb, 0, 1, 0.5, null); return(selection); }
public INoise GetLandFormFct() { //Create the Lowland base fractal with range from 0 to 1 values INoise Moisture_fractal = new FractalFbm(new Simplex(_seed), _octave, _freq, enuBaseNoiseRange.ZeroToOne); INoise ClampedValue = new Clamp(Moisture_fractal, 0, 1); INoise Moisture_fractal_biased = new Gain(ClampedValue, 0.6); INoise Moisture_fractal_Offset = new ScaleOffset(Moisture_fractal_biased, 1, 0.1); INoise ClampedValue2 = new Clamp(Moisture_fractal_Offset, 0, 1); return(ClampedValue2); //INoise TempOffset = new ScaleOffset(new Voronoi2(_seed, _freq, 0.6, new ScaleOffset(new FractalFbm(new Perlin(12345), 3, 2), 0.4, 0.0)), 1.0, 1.0); // + 1 //INoise TempScale = new ScaleOffset(TempOffset, 0.5, 0.0); // / 2 //INoise ClampedValue = new Clamp(TempScale, 0, 1); //return ClampedValue; }
public static ModuleBase CavesAndMountains(uint seed = 10000) { AccidentalNoise.Gradient ground_gradient = new AccidentalNoise.Gradient(0, 0, 0, 1); // lowlands Fractal lowland_shape_fractal = new Fractal(FractalType.BILLOW, BasisTypes.GRADIENT, InterpTypes.QUINTIC, 2, 0.25, seed); AutoCorrect lowland_autocorrect = new AutoCorrect(lowland_shape_fractal, 0, 1); ScaleOffset lowland_scale = new ScaleOffset(.5, -0.45, lowland_autocorrect); ScaleDomain lowland_y_scale = new ScaleDomain(lowland_scale, null, 0); TranslatedDomain lowland_terrain = new TranslatedDomain(ground_gradient, null, lowland_y_scale); // highlands Fractal highland_shape_fractal = new Fractal(FractalType.FBM, BasisTypes.GRADIENT, InterpTypes.QUINTIC, 4, 2, seed); AutoCorrect highland_autocorrect = new AutoCorrect(highland_shape_fractal, 0, 1.5); ScaleOffset highland_scale = new ScaleOffset(1, 0, highland_autocorrect); ScaleDomain highland_y_scale = new ScaleDomain(highland_scale, null, 1); TranslatedDomain highland_terrain = new TranslatedDomain(ground_gradient, null, highland_y_scale); // mountains Fractal mountain_shape_fractal = new Fractal(FractalType.RIDGEDMULTI, BasisTypes.GRADIENT, InterpTypes.QUINTIC, 8, 1, seed); AutoCorrect mountain_autocorrect = new AutoCorrect(mountain_shape_fractal, -1, 1); ScaleOffset mountain_scale = new ScaleOffset(0.3, 0.3, mountain_autocorrect); ScaleDomain mountain_y_scale = new ScaleDomain(mountain_scale, null, 1); TranslatedDomain mountain_terrain = new TranslatedDomain(ground_gradient, null, mountain_y_scale); // terrain Fractal terrain_type_fractal = new Fractal(FractalType.FBM, BasisTypes.GRADIENT, InterpTypes.QUINTIC, 3, 0.125, seed); AutoCorrect terrain_autocorrect = new AutoCorrect(terrain_type_fractal, 0, 1); ScaleDomain terrain_type_y_scale = new ScaleDomain(terrain_autocorrect, null, 0); Cache terrain_type_cache = new Cache(terrain_type_y_scale); Select highland_mountain_select = new Select(terrain_type_cache, highland_terrain, mountain_terrain, 0.55, 0.2); Select highland_lowland_select = new Select(terrain_type_cache, lowland_terrain, highland_mountain_select, 0.25, 0.15); Cache highland_lowland_select_cache = new Cache(highland_lowland_select); Select ground_select = new Select(highland_lowland_select_cache, 0, 1, 0.5, null); // caves Fractal cave_shape = new Fractal(FractalType.RIDGEDMULTI, BasisTypes.GRADIENT, InterpTypes.QUINTIC, 1, 2, seed); Bias cave_attenuate_bias = new Bias(highland_lowland_select_cache, 0.9); Combiner cave_shape_attenuate = new Combiner(CombinerTypes.MULT, cave_shape, cave_attenuate_bias); Fractal cave_perturb_fractal = new Fractal(FractalType.FBM, BasisTypes.GRADIENT, InterpTypes.QUINTIC, 6, 3, seed); ScaleOffset cave_perturb_scale = new ScaleOffset(1, 0, cave_perturb_fractal); TranslatedDomain cave_perturb = new TranslatedDomain(cave_shape_attenuate, cave_perturb_scale, null); Select cave_select = new Select(cave_perturb, 1, 0, 0.4, 0); return(new Combiner(CombinerTypes.MULT, cave_select, ground_select) as ModuleBase); }
public INoise GetLandFormFct() { //REM //The various parameters value here are scaled for a gradient being feed by 0 to 1 input value. //When this gradient is configured to recevied other value range then some parameters needs to be rescaled //That's the reason for using this _groundGradientTyped.AdjustY value //This way no matter the the Gradient Range, the values impacting it will be rescaled. INoise shape1_fractal = new FractalRidgedMulti(new Perlin(_seed), 1, 1.2); INoise shape1_base = new Select(0, shape1_fractal, shape1_fractal, 0.75, 0.0); INoise shape2_fractal = new FractalRidgedMulti(new Perlin(_seed + 12345), 1, 1.3); INoise shape2_base = new Select(0, shape2_fractal, shape2_fractal, 0.75, 0.0); Combiner ShapeMult = new Combiner(Combiner.CombinerType.Add); ShapeMult.Noises.Add(shape1_base); ShapeMult.Noises.Add(shape2_base); INoise CacheShapeMult = new Cache <INoise>(ShapeMult); INoise rescaledShapeMult = new ScaleOffset(CacheShapeMult, 0.6, 0); INoise clamping_base = new Select(0, rescaledShapeMult, CacheShapeMult, 0.14, 0.0); INoise turbX_fractal = new FractalFbm(new Perlin(_seed + 1), 3, 3); INoise turbY_fractal = new FractalFbm(new Perlin(_seed + 2), 3, 3); INoise turbZ_fractal = new FractalFbm(new Perlin(_seed + 3), 3, 3); INoise CaveTurb = new Turbulence(clamping_base, turbX_fractal, turbY_fractal, turbZ_fractal); //INoise landscape = new Bias(_mainLandscape, 0.45); Combiner underground_Attenuated = new Combiner(Combiner.CombinerType.Multiply); underground_Attenuated.Noises.Add(CaveTurb); underground_Attenuated.Noises.Add(_mainLandscape); //Merge the Water landForm with the surface landForm INoise world_select = new Select(0.0, underground_Attenuated, _islandCtrl, 0.01, 0.0); //Merge Plains with Midland return(world_select); }
public static ModuleBase Mountains() { Gradient ground_gradient = new Gradient(0, 0, 0, 1); Fractal ground_shape_fractal = new Fractal(FractalType.FBM, BasisTypes.GRADIENT, InterpTypes.QUINTIC, 6, 2, null); ScaleOffset ground_scale = new ScaleOffset(0.5, 0, ground_shape_fractal); ScaleDomain ground_scale_y = new ScaleDomain(ground_scale, null, 0); TranslatedDomain ground_perturb = new TranslatedDomain(ground_gradient, null, ground_scale_y); Fractal ground_overhang_fractal = new Fractal(FractalType.FBM, BasisTypes.GRADIENT, InterpTypes.QUINTIC, 6, 2, 23434); ScaleOffset ground_overhang_scale = new ScaleOffset(0.2, 0, ground_overhang_fractal); TranslatedDomain ground_overhang_perturb = new TranslatedDomain(ground_perturb, ground_overhang_scale, null); Select selection = new Select(ground_overhang_perturb, 0, 1, 0.5, null); return(selection as ModuleBase); }
public INoise GetLandFormFct() { //REM //The various parameters value here are scaled for a gradient being feed by 0 to 1 input value. //When this gradient is configured to recevied other value range then some parameters needs to be rescaled //That's the reason for using this _groundGradientTyped.AdjustY value //This way no matter the the Gradient Range, the values impacting it will be rescaled. //Create the Lowland base fractal with range from 0 to 1 values INoise ocean_shape_fractal = new FractalFbm(new Simplex(_seed), 3, 3, enuBaseNoiseRange.ZeroToOne); //Rescale + offset the output result ==> Wil modify the Scope of output range value INoise ocean_scale = new ScaleOffset(ocean_shape_fractal, 0.20 * _groundGradientTyped.AdjustY, 0.08 * _groundGradientTyped.AdjustY); //Force the Fractal to be used as 2D Noise, I don't need to 3th dimension INoise ocean_y_scale = new NoiseAccess(ocean_scale, NoiseAccess.enuDimUsage.Noise2D, true); //Offset the ground_gradient ( = create turbulance) to the Y scale of the gradient. input value INoise ocean_terrain = new Turbulence(_groundGradient, 0, ocean_y_scale); return(ocean_terrain); }
public Form1() { InitializeComponent(); Bitmap bitmap = new Bitmap(pictureBox1.Width, pictureBox1.Height); Gradient ground_gradient = new Gradient(0, 0, 0, 1); #region lowlands Fractal lowland_shape_fractal = new Fractal(FractalType.BILLOW, BasisTypes.GRADIENT, InterpTypes.QUINTIC, 2, 0.25, null); AutoCorrect lowland_autocorrect = new AutoCorrect(lowland_shape_fractal, 0, 1); ScaleOffset lowland_scale = new ScaleOffset(0.125, -0.45, lowland_autocorrect); ScaleDomain lowland_y_scale = new ScaleDomain(lowland_scale, null, 0); TranslatedDomain lowland_terrain = new TranslatedDomain(ground_gradient, null, lowland_y_scale); #endregion #region highlands Fractal highland_shape_fractal = new Fractal(FractalType.FBM, BasisTypes.GRADIENT, InterpTypes.QUINTIC, 4, 2, null); AutoCorrect highland_autocorrect = new AutoCorrect(highland_shape_fractal, -1, 1); ScaleOffset highland_scale = new ScaleOffset(0.25, 0, highland_autocorrect); ScaleDomain highland_y_scale = new ScaleDomain(highland_scale, null, 0); TranslatedDomain highland_terrain = new TranslatedDomain(ground_gradient, null, highland_y_scale); #endregion #region mountains Fractal mountain_shape_fractal = new Fractal(FractalType.RIDGEDMULTI, BasisTypes.GRADIENT, InterpTypes.QUINTIC, 8, 1, null); AutoCorrect mountain_autocorrect = new AutoCorrect(mountain_shape_fractal, -1, 1); ScaleOffset mountain_scale = new ScaleOffset(0.3, 0.15, mountain_autocorrect); ScaleDomain mountain_y_scale = new ScaleDomain(mountain_scale, null, 0.15); TranslatedDomain mountain_terrain = new TranslatedDomain(ground_gradient, null, mountain_y_scale); #endregion #region terrain Fractal terrain_type_fractal = new Fractal(FractalType.FBM, BasisTypes.GRADIENT, InterpTypes.QUINTIC, 3, 0.125, null); AutoCorrect terrain_autocorrect = new AutoCorrect(terrain_type_fractal, 0, 1); ScaleDomain terrain_type_y_scale = new ScaleDomain(terrain_autocorrect, null, 0); Cache terrain_type_cache = new Cache(terrain_type_y_scale); Select highland_mountain_select = new Select(terrain_type_cache, highland_terrain, mountain_terrain, 0.55, 0.2); Select highland_lowland_select = new Select(terrain_type_cache, lowland_terrain, highland_mountain_select, 0.25, 0.15); Cache highland_lowland_select_cache = new Cache(highland_lowland_select); Select ground_select = new Select(highland_lowland_select_cache, 0, 1, 0.5, null); #endregion #region caves Fractal cave_shape = new Fractal(FractalType.RIDGEDMULTI, BasisTypes.GRADIENT, InterpTypes.QUINTIC, 1, 4, null); Bias cave_attenuate_bias = new Bias(highland_lowland_select_cache, 0.65); Combiner cave_shape_attenuate = new Combiner(CombinerTypes.MULT, cave_shape, cave_attenuate_bias); Fractal cave_perturb_fractal = new Fractal(FractalType.FBM, BasisTypes.GRADIENT, InterpTypes.QUINTIC, 6, 3, null); ScaleOffset cave_perturb_scale = new ScaleOffset(0.5, 0, cave_perturb_fractal); TranslatedDomain cave_perturb = new TranslatedDomain(cave_shape_attenuate, cave_perturb_scale, null); Select cave_select = new Select(cave_perturb, 1, 0, 0.75, 0); #endregion Combiner gound_cave_multiply = new Combiner(CombinerTypes.MULT, cave_select, ground_select); //EXAMPLE 1 //Gradient ground_gradient = new Gradient(0, 0, 0, 1); //Fractal ground_shape_fractal = new Fractal(FractalType.FBM, // BasisTypes.GRADIENT, // InterpTypes.QUINTIC, // 6, 2, null); //ScaleOffset ground_scale = new Accidental.ScaleOffset(0.5, 0, ground_shape_fractal); //ScaleDomain ground_scale_y = new ScaleDomain(null, 0, ground_scale); //TranslatedDomain ground_perturb = new TranslatedDomain(ground_gradient, null, ground_scale_y); //Fractal ground_overhang_fractal = new Fractal(FractalType.FBM, // BasisTypes.GRADIENT, // InterpTypes.QUINTIC, // 6, 2, 23434); //ScaleOffset ground_overhang_scale = new ScaleOffset(0.2, 0, ground_overhang_fractal); //TranslatedDomain ground_overhang_perturb = new TranslatedDomain(ground_perturb, ground_overhang_scale, null); //Select ground_select = new Select(ground_overhang_perturb, 0, 1, 0.5, null); //EXAMPLE 2 //Fractal cave_shape = new Accidental.Fractal(FractalType.RIDGEDMULTI, BasisTypes.GRADIENT, InterpTypes.QUINTIC, 1, 2, 4533); //Select cave_select = new Accidental.Select(cave_shape, 1, 0, 0.6, 0); //Fractal cave_perturb_fractal = new Fractal(FractalType.FBM, BasisTypes.GRADIENT, InterpTypes.QUINTIC, 6, 3, null); //ScaleOffset cave_perturb_scale = new ScaleOffset(0.25, 0, cave_perturb_fractal); //TranslatedDomain cave_perturb = new TranslatedDomain(cave_select, cave_perturb_scale, null); SMappingRanges ranges = new SMappingRanges(); //finally update our image for (int x = 0; x < bitmap.Width; x++) { for (int y = 0; y < bitmap.Height; y++) { double p = (double)x / (double)bitmap.Width; double q = (double)y / (double)bitmap.Height; double nx, ny = 0.0; nx = ranges.mapx0 + p * (ranges.mapx1 - ranges.mapx0); ny = ranges.mapy0 + q * (ranges.mapy1 - ranges.mapy0); double val = gound_cave_multiply.Get(nx * 6, ny * 3); bitmap.SetPixel(x, y, Color.Black.Lerp(Color.White, val)); } } pictureBox1.Image = bitmap; }