/// <summary> /// HelmsDeepButton is a Static method that resets the etire GIF drawing process, /// resets all cells, redraws each cell, and prints a specified ammount of frames, /// both to a form passed and to an output 'Output.gif' file. /// </summary> /// <param name="f">The form to draw the new frames to</param> /// <param name="frames">The ammount of frames to print</param> public static void HelmsDeepButton(Form1 f, int frames = 20) { Stream s = File.Create("Output.gif"); StreamWriter sw = new StreamWriter(s); GifWriter gw = new GifWriter(s, 350, 1); Random rand = new Random(); FillCells(); Bitmap m = new Bitmap(400, 400); //Graphics g = Graphics.FromImage(m); DisplayCells(f, rand, m); Graphics gg = f.CreateGraphics(); gg.DrawImage(new Bitmap("Help.png"), 400, 50); gg.Dispose(); for (int i = 0; i < frames; i++) { Debug.WriteLine(" I is " + i); Globals.PrintCells(); SetUpSiegeAnimation(rand); RunAnimation(); DisplayCells(f, rand, m, i); m.Save("temp.png", ImageFormat.Png); Globals.PrintCells(); gw.WriteFrame(m); Thread.Sleep(1000); } //g.Dispose(); m.Dispose(); gw.Dispose(); s.Close(); }
/// <summary> /// DispalyCells draws <see cref="Globals"/>'s SiegeCells array. /// Dispaly cell, for eachcell Type, decide a Solidbrush color, and then draws a /// 20x20px square in that color, modiefied by nearby lighting. This drawing takes place /// in both an external bitmap and on a refrenced <see cref="Form"/>. /// Square are drawn left to right, top to bottom /// </summary> /// <param name="f">The Windows Form to Draw on</param> /// <param name="rand">An instance of <see cref="Random"/> to generate random objects</param> /// <param name="m">The bitmap to draw to</param> /// <param name="frame">The number 'frame' that is being drawn so the Form 'f' can have it's title edited to show progress</param> public static void DisplayCells(Form1 f, Random rand, Bitmap m, int frame = 0) { int xOffset = 0; int yOffset = 0; Form1 form1 = f; form1.Text = "SiegeGen Rendering Frame " + frame; SolidBrush brush = new SolidBrush(Color.Transparent); Graphics g = Graphics.FromImage(m); Graphics gg = f.CreateGraphics(); for (int r = 0; r < Globals.siegeCells.GetLength(0); r++) { for (int i = 0; i < Globals.siegeCells.GetLength(0); i++) { switch (Globals.siegeCells[r, i].GetCellType()) { case (SiegeFunctions.CellTypes.Ground): brush.Color = Color.FromArgb(255, 178, 123, 89); break; case (SiegeFunctions.CellTypes.Wall): brush.Color = Color.FromArgb(255, 128, 128, 128); break; case (SiegeFunctions.CellTypes.WallTop): brush.Color = Color.FromArgb(255, 100, 100, 100); break; case (SiegeFunctions.CellTypes.Night): brush.Color = Color.FromArgb(255, 0, 0, 0); break; case (SiegeFunctions.CellTypes.CityProper): brush.Color = Color.FromArgb(255, 72, 72, 72); break; case (SiegeFunctions.CellTypes.Rohan): brush.Color = Color.FromArgb(255, 165, 255, 127); break; case (SiegeFunctions.CellTypes.Torch): brush.Color = Color.FromArgb(255, 255, 216, 0); break; case (SiegeFunctions.CellTypes.BackgroundCity): brush.Color = Color.FromArgb(255, 54, 54, 54); break; case (SiegeFunctions.CellTypes.Urkhai): brush.Color = Color.FromArgb(255, 48, 48, 48); break; case (SiegeFunctions.CellTypes.UrkhaiElite): brush.Color = Color.FromArgb(255, 192, 192, 192); break; case (SiegeFunctions.CellTypes.Ladder): brush.Color = Color.FromArgb(255, 127, 63, 63); break; case (SiegeFunctions.CellTypes.LadderStart): brush.Color = Color.FromArgb(255, 127, 63, 63); break; default: brush.Color = Color.FromArgb(165, 255, 0, 0); break; } //Add Light between 10&&15 if torch nearby Non-ground,non-torch if (GetNearbyCells(r, i, SiegeFunctions.CellTypes.Torch) && Globals.siegeCells[r, i].GetCellType() != SiegeFunctions.CellTypes.Torch && Globals.siegeCells[r, i].GetCellType() != SiegeFunctions.CellTypes.Ground && Globals.siegeCells[r, i].GetCellType() != SiegeFunctions.CellTypes.BackgroundCity) { int Lightchange = rand.Next(10) + 5; brush.Color = Color.FromArgb(255, (brush.Color.R + Lightchange) % 255, (brush.Color.B + Lightchange) % 255, (brush.Color.G + Lightchange) % 255); } //If torch and nearbycell cityBackground, randomize brightness if (GetNearbyCells(r, i, SiegeFunctions.CellTypes.BackgroundCity) && Globals.siegeCells[r, i].GetCellType() == SiegeFunctions.CellTypes.Torch) { int Lightchange = rand.Next(100) + 155; brush.Color = Color.FromArgb(255, Lightchange, Lightchange, 0); } //If WOunded, change color to red if (Globals.siegeCells[r, i].wounded) { brush.Color = Color.FromArgb(255, (brush.Color.R + 100) % 255, brush.Color.G % 100, brush.Color.B % 100); } g.FillRectangle(brush, new Rectangle(new Point((20 * r) + xOffset, (20 * i) + yOffset), new Size(20, 20))); gg.FillRectangle(brush, new Rectangle(new Point((20 * r) + xOffset, (20 * i) + yOffset), new Size(20, 20))); if (Globals.siegeCells[r, i].GetCellType() == SiegeFunctions.CellTypes.Urkhai || Globals.siegeCells[r, i].GetCellType() == SiegeFunctions.CellTypes.Rohan) { Pen smotherPen = new Pen(Color.LightGray); for (int z = 0; z < 1; z++) { if (rand.Next(3) > 1) { int one = rand.Next(20) + (20 * r) + xOffset; int two = rand.Next(20) + (20 * i) + yOffset; int three = one + (rand.Next(10) - 5); int four = two + (rand.Next(10) - 5); if (three < 0) { three = 0; } if (four < 0) { four = 0; } g.DrawLine(smotherPen, one, two, three, four); gg.DrawLine(smotherPen, one, two, three, four); } } } } } f.Update(); //Thread.Sleep(1000); gg.Dispose(); g.Dispose(); }