/// <summary> /// Generate a white noise <see cref="HeightMap"/> /// </summary> public override HeightMap Generate() { var maxLength = Math.Max(Dimensions.Height, Dimensions.Width); var noise = new DiamondSquareNoise(Seed); var result = noise.Generate(maxLength, RandomnessFactor); var resizedResult = MathHelper.Copy(result, Dimensions.Height, Dimensions.Width); var map = new HeightMap(resizedResult); return(map); }
public HeightMap(bool pPerlin, int pSize) { _size = pSize; if (pPerlin) { var n = new PerlinNoise(pSize); _map = n.Generate(4, .7f, .4f, .3f, .1f); } else { var n = new DiamondSquareNoise(pSize); _map = n.Generate(0, 5, .5f); float maxHeight = 0; float maxDepth = 1; for (int x = 0; x < pSize; x++) { for (int y = 0; y < pSize; y++) { if (_map[x, y] > maxHeight) { maxHeight = _map[x, y]; } if (_map[x, y] < maxDepth) { maxDepth = _map[x, y]; } } } //Scale all points so they are within max/min maxDepth = Math.Abs(maxDepth); for (int x = 0; x < pSize; x++) { for (int y = 0; y < pSize; y++) { if (_map[x, y] < 0) { _map[x, y] = _map[x, y] / maxDepth; } else if (_map[x, y] > 0) { _map[x, y] = _map[x, y] / maxHeight; } } } } }
public DiamondSquare2D(int width, int height, float roughness = 1f, Func <double, double> decayFunction = null, System.Random random = null) : base(width, height) { DiamondSquareNoise.DiamondSquareArguments args = new DiamondSquareNoise.DiamondSquareArguments(); args.width = width; args.height = height; args.roughness = roughness; args.decayFunction = decayFunction; args.random = random; double[,] noise = DiamondSquareNoise.GenerateNoise(args); float min = float.PositiveInfinity; float max = float.NegativeInfinity; for (int x = 0, y = 0; y < this.Height; y += ++x / this.Width, x %= this.Width) { this[y, x] = (float)noise[y, x]; min = Math.Min(min, this[y, x]); max = Math.Max(max, this[y, x]); } }