private void ImportClick() { OpenFileDialog f = new OpenFileDialog(); var result = f.ShowDialog(); string fullpath = @"e:\g.png"; if (result == false) { return; } fullpath = f.FileName; var original = Image.FromFile(fullpath); original = ResizePicture(original, 40, 16); Bitmap bmp = new Bitmap(original); var rectangle = new Rectangle(0, 0, original.Width, original.Height); var bmp1bpp = bmp.Clone(rectangle, PixelFormat.Format1bppIndexed); bmp1bpp.Save(@"e:\image.bmp"); bool[,] datas = new bool[40, 16]; for (int i = 0; i < bmp1bpp.Width; i++) { string line = string.Empty; for (int j = 0; j < bmp1bpp.Height; j++) { Color pixel = bmp1bpp.GetPixel(i, j); bool r = !((pixel.R == Color.White.R) && (pixel.G == Color.White.G) && (pixel.B == Color.White.B)); line += r ? "x" : "_"; datas[i, j] = r; } line += Environment.NewLine; } ModelHelper.log(datas); var line1 = HelperMatriceListConvertor.ConvertToList(datas); steps.ForEach(x => x.Apply(line1)); ModelHelper.log(line1); }
static void Main(string[] args) { string[] input = { "rect 1x1", "rotate row y=0 by 5", "rect 1x1", "rotate row y=0 by 5", "rect 1x1", "rotate row y=0 by 5", "rect 1x1", "rotate row y=0 by 5", "rect 1x1", "rotate row y=0 by 2", "rect 1x1", "rotate row y=0 by 2", "rect 1x1", "rotate row y=0 by 3", "rect 1x1", "rotate row y=0 by 3", "rect 2x1", "rotate row y=0 by 2", "rect 1x1", "rotate row y=0 by 3", "rect 2x1", "rotate row y=0 by 2", "rect 1x1", "rotate row y=0 by 3", "rect 2x1", "rotate row y=0 by 5", "rect 4x1", "rotate row y=0 by 5", "rotate column x=0 by 1", "rect 4x1", "rotate row y=0 by 10", "rotate column x=5 by 2", "rotate column x=0 by 1", "rect 9x1", "rotate row y=2 by 5", "rotate row y=0 by 5", "rotate column x=0 by 1", "rect 4x1", "rotate row y=2 by 5", "rotate row y=0 by 5", "rotate column x=0 by 1", "rect 4x1", "rotate column x=40 by 1", "rotate column x=27 by 1", "rotate column x=22 by 1", "rotate column x=17 by 1", "rotate column x=12 by 1", "rotate column x=7 by 1", "rotate column x=2 by 1", "rotate row y=2 by 5", "rotate row y=1 by 3", "rotate row y=0 by 5", "rect 1x3", "rotate row y=2 by 10", "rotate row y=1 by 7", "rotate row y=0 by 2", "rotate column x=3 by 2", "rotate column x=2 by 1", "rotate column x=0 by 1", "rect 4x1", "rotate row y=2 by 5", "rotate row y=1 by 3", "rotate row y=0 by 3", "rect 1x3", "rotate column x=45 by 1", "rotate row y=2 by 7", "rotate row y=1 by 10", "rotate row y=0 by 2", "rotate column x=3 by 1", "rotate column x=2 by 2", "rotate column x=0 by 1", "rect 4x1", "rotate row y=2 by 13", "rotate row y=0 by 5", "rotate column x=3 by 1", "rotate column x=0 by 1", "rect 4x1", "rotate row y=3 by 10", "rotate row y=2 by 10", "rotate row y=0 by 5", "rotate column x=3 by 1", "rotate column x=2 by 1", "rotate column x=0 by 1", "rect 4x1", "rotate row y=3 by 8", "rotate row y=0 by 5", "rotate column x=3 by 1", "rotate column x=2 by 1", "rotate column x=0 by 1", "rect 4x1", "rotate row y=3 by 17", "rotate row y=2 by 20", "rotate row y=0 by 15", "rotate column x=13 by 1", "rotate column x=12 by 3", "rotate column x=10 by 1", "rotate column x=8 by 1", "rotate column x=7 by 2", "rotate column x=6 by 1", "rotate column x=5 by 1", "rotate column x=3 by 1", "rotate column x=2 by 2", "rotate column x=0 by 1", "rect 14x1", "rotate row y=1 by 47", "rotate column x=9 by 1", "rotate column x=4 by 1", "rotate row y=3 by 3", "rotate row y=2 by 10", "rotate row y=1 by 8", "rotate row y=0 by 5", "rotate column x=2 by 2", "rotate column x=0 by 2", "rect 3x2", "rotate row y=3 by 12", "rotate row y=2 by 10", "rotate row y=0 by 10", "rotate column x=8 by 1", "rotate column x=7 by 3", "rotate column x=5 by 1", "rotate column x=3 by 1", "rotate column x=2 by 1", "rotate column x=1 by 1", "rotate column x=0 by 1", "rect 9x1", "rotate row y=0 by 20", "rotate column x=46 by 1", "rotate row y=4 by 17", "rotate row y=3 by 10", "rotate row y=2 by 10", "rotate row y=1 by 5", "rotate column x=8 by 1", "rotate column x=7 by 1", "rotate column x=6 by 1", "rotate column x=5 by 1", "rotate column x=3 by 1", "rotate column x=2 by 2", "rotate column x=1 by 1", "rotate column x=0 by 1", "rect 9x1", "rotate column x=32 by 4", "rotate row y=4 by 33", "rotate row y=3 by 5", "rotate row y=2 by 15", "rotate row y=0 by 15", "rotate column x=13 by 1", "rotate column x=12 by 3", "rotate column x=10 by 1", "rotate column x=8 by 1", "rotate column x=7 by 2", "rotate column x=6 by 1", "rotate column x=5 by 1", "rotate column x=3 by 1", "rotate column x=2 by 1", "rotate column x=1 by 1", "rotate column x=0 by 1", "rect 14x1", "rotate column x=39 by 3", "rotate column x=35 by 4", "rotate column x=20 by 4", "rotate column x=19 by 3", "rotate column x=10 by 4", "rotate column x=9 by 3", "rotate column x=8 by 3", "rotate column x=5 by 4", "rotate column x=4 by 3", "rotate row y=5 by 5", "rotate row y=4 by 5", "rotate row y=3 by 33", "rotate row y=1 by 30", "rotate column x=48 by 1", "rotate column x=47 by 5", "rotate column x=46 by 5", "rotate column x=45 by 1", "rotate column x=43 by 1", "rotate column x=38 by 3", "rotate column x=37 by 3", "rotate column x=36 by 5", "rotate column x=35 by 1", "rotate column x=33 by 1", "rotate column x=32 by 5", "rotate column x=31 by 5", "rotate column x=30 by 1", "rotate column x=23 by 4", "rotate column x=22 by 3", "rotate column x=21 by 3", "rotate column x=20 by 1", "rotate column x=12 by 2", "rotate column x=11 by 2", "rotate column x=3 by 5", "rotate column x=2 by 5", "rotate column x=1 by 3", "rotate column x=0 by 4" }; var commands = input.Select(Command.Parse).ToList(); int fieldWidth = 50; int fieldHeight = 6; bool[,] field = new bool[fieldHeight, fieldWidth]; foreach (var cmd in commands) { field.Apply(cmd); } int result1 = field.Cast <bool>().Count(cell => cell); Console.WriteLine("Answer 1: {0}", result1); Console.WriteLine("Answer 2:"); Print(field); Console.ReadKey(); }