public void Init(LockBitmap bmp, float sizeDelta, GeneratedTerrainMap generatedMap) { provincesDelta = sizeDelta; if (provincesDelta < 0.5f) { provincesDelta *= 1.8f; } LoadProvinceColors(); Color col = Color.FromArgb(255, 1, 0, 0); int r = 1; int g = 0; int b = 0; float highmountainLevel = 0.7f; float DivNoise = 1200.0f * (generatedMap.Height / 2048.0f); NoiseGenerator noiseH = new NoiseGenerator(); NoiseGenerator noiseM = new NoiseGenerator(); generatedMap.Map.LockBits(); generatedMap.MoistureMap.LockBits(); generatedMap.HeatMap.LockBits(); SolidBrush br = new SolidBrush(Color.Black); using (Graphics gg = Graphics.FromImage(bmp.Source)) for (int x = 0; x < generatedMap.Map.Width; x++) { for (int y = 0; y < generatedMap.Map.Height; y++) { float height = generatedMap.Map.GetHeight(x, y); if (height >= highmountainLevel * 255) { gg.FillEllipse(br, new Rectangle(x - 2, y - 2, 4, 4)); } } } LockBitmap bmp2 = new LockBitmap(new Bitmap(bmp.Source)); bmp2.LockBits(); using (Graphics gg = Graphics.FromImage(bmp.Source)) for (int x = 0; x < generatedMap.Map.Width; x++) { for (int y = 0; y < generatedMap.Map.Height; y++) { float heat = generatedMap.HeatMap.GetHeight(x, y) / 255.0f; // + (Rand.Next(-30, 30) / 8000.0f); float moisture = generatedMap.MoistureMap.GetHeight(x / 4, y / 4) / 255.0f; // + (Rand.Next(-30, 30) / 8000.0f); float no = (float)((float)((noiseH.Noise(x / DivNoise / 8, y / DivNoise / 8)) - 0.5f) * 0.2); heat += no * 1.4f; moisture -= no * 0.5f; float desertLevel = 0.48f; float desertDry = 0.28f; bool hot = heat > desertLevel; bool dry = moisture <= desertDry; if (hot && dry && bmp2.GetPixel(x, y) == Color.FromArgb(255, 130, 158, 75)) { gg.FillEllipse(br, new Rectangle(x - 5, y - 5, 10, 10)); } } } bmp2.UnlockBits(); generatedMap.Map.UnlockBits(); generatedMap.MoistureMap.UnlockBits(); generatedMap.HeatMap.UnlockBits(); // bmp.Save24(Globals.MapOutputTotalDir + "testprovinces.bmp"); bmp.LockBits(); UnsafeQueueLinearFloodFiller filler = new UnsafeQueueLinearFloodFiller(null); filler.Bitmap = bmp; Bitmap = bmp; for (int x = 0; x < bmp.Width; x++) { for (int y = 0; y < bmp.Height; y++) { Color pix = bmp.GetPixel(x, y); if (pix == Color.FromArgb(255, 69, 91, 186) || pix == Color.FromArgb(255, 130, 158, 75)) { areaColors.Add(col); filler.FillColor = col; filler.FloodFill(new Point(x, y)); bool valid = false; foreach (var point in filler.pts) { for (int yy = -1; yy <= 1; yy++) { for (int xx = -1; xx <= 1; xx++) { if (xx == 0 && yy == 0) { continue; } if (point.X + xx < 0 || point.Y + yy < 0 || point.X + xx >= bmp.Width || point.Y + yy >= bmp.Height) { continue; } var ccc = bmp.GetPixel(xx + point.X, yy + point.Y); if (col.R == ccc.R && ccc.G == col.G && ccc.B == col.B) { continue; } if (ccc.R > 0 || ccc.G > 0 || ccc.B > 0) { valid = true; } } } } if (!valid) { filler.FillColor = Color.Black; filler.FloodFill(new Point(x, y)); continue; } { int numProvinces = (int)(filler.pts.Count / (3000)); if (pix == Color.FromArgb(255, 130, 158, 75)) { numProvinces = (int)(numProvinces * sizeDelta); } if (numProvinces == 0) { numProvinces = 1; } if (pix != Color.FromArgb(255, 130, 158, 75)) { numProvinces /= 6; if (numProvinces < 1) { numProvinces = 1; } } CreateProvinces(numProvinces, col, filler.pts, bmp.Width, bmp.Height, bmp, pix != Color.FromArgb(255, 130, 158, 75)); FixupProvinces(col, filler, bmp); } r += 1; if (r > 255) { r = 0; g += 1; } if (g > 255) { g = 0; b += 1; } col = Color.FromArgb(255, r, g, b); } } } provinces = provinces.Distinct().ToList(); foreach (var province in provinces) { province.points.Clear(); colorProvinceMap[province.Color] = province; } for (int x = 0; x < bmp.Width; x++) { for (int y = 0; y < bmp.Height; y++) { Color pix = bmp.GetPixel(x, y); if (colorProvinceMap.ContainsKey(pix)) { colorProvinceMap[pix].points.Add(new Point(x, y)); } else { } } } CalculateDetails(); bmp.UnlockDirect(); // bmp.Save24("C:\\Users\\LEMMY\\Documents\\terrainNew.bmp"); }
public void Init(LockBitmap bmp, float sizeDelta, GeneratedTerrainMap generatedMap) { provincesDelta = sizeDelta; if (provincesDelta < 0.5f) { provincesDelta *= 1.8f; } LoadProvinceColors(); Color col = FromArgb(255, 1, 0, 0); int r = 1; int g = 0; int b = 0; float highmountainLevel = 0.7f; float DivNoise = 1200.0f * (generatedMap.Height / 2048.0f); NoiseGenerator noiseH = new NoiseGenerator(); generatedMap.Map.LockBits(); generatedMap.MoistureMap.LockBits(); generatedMap.HeatMap.LockBits(); SolidBrush br = new SolidBrush(Black); using (Graphics gg = Graphics.FromImage(bmp.Source)) { for (int x = 0; x < generatedMap.Map.Width; x++) { for (int y = 0; y < generatedMap.Map.Height; y++) { float height = generatedMap.Map.GetHeight(x, y); if (height >= highmountainLevel * 255) { gg.FillEllipse(br, new Rectangle(x - 2, y - 2, 4, 4)); } } } } LockBitmap bmp2 = new LockBitmap(new Bitmap(bmp.Source)); bmp2.LockBits(); using (Graphics gg = Graphics.FromImage(bmp.Source)) { for (int x = 0; x < generatedMap.Map.Width; x++) { for (int y = 0; y < generatedMap.Map.Height; y++) { float heat = generatedMap.HeatMap.GetHeight(x, y) / 255.0f; // + (Rand.Next(-30, 30) / 8000.0f); float moisture = generatedMap.MoistureMap.GetHeight(x / 4, y / 4) / 255.0f; // + (Rand.Next(-30, 30) / 8000.0f); float no = (float)((float)((noiseH.Noise(x / DivNoise / 8, y / DivNoise / 8)) - 0.5f) * 0.2); heat += no * 1.4f; moisture -= no * 0.5f; float desertLevel = 0.48f; float desertDry = 0.28f; bool hot = heat > desertLevel; bool dry = moisture <= desertDry; if (hot && dry && bmp2.GetPixel(x, y) == FromArgb(255, 130, 158, 75)) { gg.FillEllipse(br, new Rectangle(x - 5, y - 5, 10, 10)); } } } } bmp2.UnlockBits(); generatedMap.Map.UnlockBits(); generatedMap.MoistureMap.UnlockBits(); generatedMap.HeatMap.UnlockBits(); bmp.LockBits(); var filler = new UnsafeQueueLinearFloodFiller(null) { Bitmap = bmp }; Bitmap = bmp; for (int x = 0; x < bmp.Width; x++) { for (int y = 0; y < bmp.Height; y++) { Color pix = bmp.GetPixel(x, y); if (pix == FromArgb(255, 69, 91, 186) || pix == FromArgb(255, 130, 158, 75)) { col = setColor(bmp, sizeDelta, col, filler, x, y, pix, ref r, ref g, ref b); } } } provinces = provinces.Distinct().ToList(); foreach (var province in provinces) { province.points.Clear(); colorProvinceMap[province.Color] = province; } CalculateProvinceColor(bmp); CalculateDetails(); bmp.UnlockDirect(); }