public static void Generate(GraphicsDevice gd, float[][] arr, string algorithm = "") { try { int width = arr.Length; int height = arr.Length; if (!String.IsNullOrWhiteSpace(algorithm)) { algorithm = algorithm + " - "; } using (Texture2D image = new Texture2D(gd, width, height)) { var copy2D = arr.Select(a => a.ToArray()).ToArray(); var imgArr = ToOneDimentionalArray(PostModifications.Normalize(copy2D, width, 255)); image.SetData(ToGrayScale(imgArr, width, height)); if (!Directory.Exists("./HeightMaps/")) { Directory.CreateDirectory("./HeightMaps/"); } using (Stream stream = File.Create("./HeightMaps/" + algorithm + DateTime.Now.ToString("H;mm;ss") + ".png")) { image.SaveAsPng(stream, width, height); } } } catch { } }
public IGameObject Generate() { var arr = Utils.GetEmptyArray(Size, Size, 0); for (int i = 0; i < Size; i++) { for (int j = 0; j < Size; j++) { arr[i][j] = GetCellular(i, j); } } arr = PostModifications.Normalize(arr, Size, Height); HeightMapGenerator.Generate(_graphicDevice, arr, "Voronoi (" + noiseType.ToString() + ")"); return(new PrimitiveBase(_graphicDevice, _graphicDeviceManeger, arr, Size)); }
public IGameObject Generate() { var arr = Utils.GetEmptyArray(2, 2, -1); for (var i = 0; i < arr.Length; i++) { for (var j = 0; j < arr.Length; j++) { arr[i][j] = GetRandom(); } } for (int i = 1; i < Iterations; i++) { var Divided = DivideToSquares(arr); var squaredArray = new List <float[][]>(); for (int j = 0; j < Divided.Count; j++) { var div = Square(Divided.ElementAt(j)); squaredArray.Add(div); } var middedArray = new List <float[][]>(); for (int j = 0; j < squaredArray.Count; j++) { var mid = Mid(squaredArray.ElementAt(j)); middedArray.Add(mid); } var diamondedArray = new List <float[][]>(); for (int j = 0; j < middedArray.Count; j++) { var diamond = Diamond(middedArray.ElementAt(j)); diamondedArray.Add(diamond); } arr = ConnectArrays(diamondedArray); Displacement /= 2; } arr = PostModifications.Normalize(arr, arr.Length, Height); arr = Utils.ShiftTerrain(arr); HeightMapGenerator.Generate(_graphicDevice, arr, "Diamond Square"); return(new PrimitiveBase(_graphicDevice, _graphicDeviceManeger, arr, arr.Length)); }
public IGameObject Generate() { var arr = Utils.GetEmptyArray(MapSize, MapSize); //for(int l = 0; l < 5; l++) for (int j = 0; j < Walkers; j++) { int PointX = rand.Next(0, 1024); int PointY = rand.Next(0, 1024); int Steps = rand.Next(MinSteps, MaxSteps); for (int i = 0; i < Steps; i++) { Walk(arr, ref PointX, ref PointY); } } arr = PostModifications.Smooth(arr, 1); arr = PostModifications.Normalize(arr, MapSize, Height); arr = Utils.ShiftTerrain(arr); HeightMapGenerator.Generate(_graphicDevice, arr, "Random walk"); return(new PrimitiveBase(_graphicDevice, _graphicDeviceManeger, arr, MapSize)); }