private static void GenerateBiomeMap(int chunks) { int finished = 0; Bitmap bitmap = new Bitmap(chunks * 16, chunks * 16); Bitmap heightmap = new Bitmap(chunks * 16, chunks * 16); Bitmap chunkHeight = new Bitmap(chunks * 16, chunks * 16); while (finished < chunks * chunks) { if (Finished.TryDequeue(out ChunkColumn column)) { for (int cx = 0; cx < 16; cx++) { var rx = (column.X * 16) + cx; for (int cz = 0; cz < 16; cz++) { var rz = (column.Z * 16) + cz; var biome = BiomeUtils.GetBiomeById(column.GetBiome(cx, cz)); var temp = (int)Math.Max(0, Math.Min(255, (255 * MathUtils.ConvertRange(-1f, 2f, 0f, 1f, biome.Temperature)))); var humid = (int)Math.Max(32, Math.Min(255, (255 * biome.Downfall))); bitmap.SetPixel(rx, rz, Color.FromArgb(humid, temp, 0, 255 - temp)); int height = column.GetHeight(cx, cz); chunkHeight.SetPixel(rx, rz, Color.FromArgb(height, height, height)); height = (int)Math.Max(0, Math.Min(255, (255 * MathUtils.ConvertRange(-2f, 2f, 0f, 1f, ((biome.MinHeight + biome.MaxHeight) / 2f))))); heightmap.SetPixel(rx, rz, Color.FromArgb(height, height, height)); } } Imaged++; finished++; } else { Thread.Sleep(50); } } bitmap.Save("heatmap.png", ImageFormat.Png); heightmap.Save("height.png", ImageFormat.Png); chunkHeight.Save("chunkHeight.png", ImageFormat.Png); }
private static Task GenerateHeightmap(ChunkColumn[] columns, int chunks, bool chunkHeight) { return(Task.Run(() => { Bitmap bitmap = new Bitmap(chunks * 16, chunks * 16); for (int x = 0; x < chunks; x++) { for (int z = 0; z < chunks; z++) { ChunkColumn column = columns[(x * chunks) + z]; for (int cx = 0; cx < 16; cx++) { var rx = (x * 16) + cx; for (int cz = 0; cz < 16; cz++) { var rz = (z * 16) + cz; // var height = column.GetHeight(cx, cz); // var temp = (int) Math.Max((byte)0, // Math.Min((byte)255, height)); var height = 0; if (!chunkHeight) { height = column.GetHeight(cx, cz); } else { var biome = BiomeUtils.GetBiomeById(column.GetBiome(cx, cz)); height = (int)Math.Max(0, Math.Min(255, (255 * MathUtils.ConvertRange(-2f, 2f, 0f, 1f, ((biome.MinHeight + biome.MaxHeight) / 2f))))); } bitmap.SetPixel(rx, rz, Color.FromArgb(height, height, height)); } } } } bitmap.Save(chunkHeight ? "chunkHeight.png" : "height.png", ImageFormat.Png); })); }