private void generateLandmass_Click(object sender, EventArgs e) { map = new GeneratedTerrainMap(); if (randomize.Checked) { seedBox.Value = Rand.Next(10000000); } int seed = (int)seedBox.Value; usedSeed = seed; int w = 3072; if (mapvlarge.Checked) { w = 4096; } if (maplarge.Checked) { w = 3200; } if (mapnorm.Checked) { w = 3072; } if (mapsmall.Checked) { w = 2048; } map.Init(w / 10, 2048 / 10, usedSeed); preview.Image = map.Map.Source; exportButton.Enabled = true; }
private void generateFromDraw_Click(object sender, EventArgs e) { generateDrawn.Enabled = true; int ow = 1; int oh = 1; int w = 3072; int h = 2048; if (mapvlarge.Checked) { w = 4096; } if (maplarge.Checked) { w = 3200; } if (mapnorm.Checked) { w = 3072; } if (mapsmall.Checked) { w = 2048; } { Bitmap bmp = new Bitmap(w / 2, h / 2, PixelFormat.Format24bppRgb); Bitmap bmp2 = new Bitmap(w / 2, h / 2, PixelFormat.Format24bppRgb); LockBitmap lbmp2 = new LockBitmap(bmp2); LockBitmap lbmp = new LockBitmap(bmp); float deltaX = w / (float)preview.Width; float deltaY = h / (float)preview.Height; lbmp.LockBits(); lbmp2.LockBits(); landProxyBitmap.LockBits(); mountainProxyBitmap.LockBits(); for (int x = 0; x < bmp.Width; x++) { for (int y = 0; y < bmp.Height; y++) { float dx = mountainProxyBitmap.Width / (float)bmp.Width; float dy = mountainProxyBitmap.Height / (float)bmp.Height; var col = mountainProxyBitmap.GetPixel((int)(x * dx), (int)(y * dy)); var col2 = landProxyBitmap.GetPixel((int)(x * dx), (int)(y * dy)); int xx = x; int yy = y; if (col.R > 0 && col.A > 0) { lbmp.SetPixel(xx, yy, Color.White); } else { lbmp.SetPixel(xx, yy, Color.Black); } if (col2.R != 69 && col2.A > 0) { lbmp2.SetPixel(xx, yy, Color.White); } else { lbmp2.SetPixel(xx, yy, Color.Black); } } } lbmp2.UnlockBits(); lbmp.UnlockBits(); landProxyBitmap.UnlockBits(); mountainProxyBitmap.UnlockBits(); /* Graphics g = Graphics.FromImage(bmp); * * foreach (var drawCommand in MountainCommands) * { * var r = new Rectangle(drawCommand.Point.X - drawCommand.Radius, drawCommand.Point.Y - drawCommand.Radius, * drawCommand.Radius * 2, drawCommand.Radius * 2); * * Rectangle rect = new Rectangle((int)(r.X * deltaX), (int)(r.Y * deltaY), (int)((r.Right * deltaX) - (r.Left * deltaX)), (int)((r.Bottom * deltaY) - r.Top * deltaY)); * * g.FillEllipse(a, rect); * } */ int rand = 32; if (randMed.Checked) { rand = 32; } if (randHigh.Checked) { rand = 32; } ow = bmp.Width; oh = bmp.Height; lbmp.ResizeImage(ow / rand, oh / rand); lbmp.ResizeImage(ow * 2, oh * 2); mountainBitmap = lbmp.Source; rand = 8; BitmapSelect.Randomness = 0.75f; if (randMed.Checked) { rand = 16; BitmapSelect.Randomness = 1f; } if (randHigh.Checked) { rand = 64; BitmapSelect.Randomness = 1f; } if (randMin.Checked) { rand = 2; BitmapSelect.Randomness = 0.5f; } ow = bmp2.Width; oh = bmp2.Height; lbmp2.ResizeImage(ow / rand, oh / rand); lbmp2.ResizeImage(ow * 2, oh * 2); landBitmap = lbmp2.Source; } map = new GeneratedTerrainMap(); int seed = Rand.Next(1000000); LockBitmap lBit = new LockBitmap(landBitmap); LockBitmap mBit = new LockBitmap(mountainBitmap); map.Init(ow / 4, oh / 4, lBit, lBit, mBit, seed); lBit.UnlockBits(); mBit.UnlockBits(); DrawnSeed = seed; landBitmap = map.Map.Source; landBitmapOut = lBit.Source; mountainBitmap = mBit.Source; preview.Invalidate(); }