public Crystal(CrystalMapping matrix, int ruleNumber)
 {
     source = matrix;
     source.SetCellColor(source.GetLength() / 2, source.GetLength() / 2, 1);
     target = new CrystalMapping(source.GetLength());
     rule = new CrystalRule(ruleNumber);
 }
 // Копирование массива
 public void Copy(CrystalMapping matrix)
 {
     if (matrix.matrix.Length != this.matrix.Length)
         throw new ArgumentOutOfRangeException("CrystalMapping::Copy()");
     Parallel.For(0, this.matrix.Length, (int i) =>
     {
         Parallel.For(0, this.matrix.Length, (int k) =>
         {
             this.matrix[i][k] = matrix.matrix[i][k];
         });
     });
 }
 static void Main(string[] args)
 {
     int automataID = GetAutomataID();
     int iterationCount = GetIterationCount();
     turmiteMatrix = new TurmiteMatrix(MATRIX_RANGE);
     crystalMatrix = new CrystalMapping(MATRIX_RANGE);
     if (automataID >= 0 && automataID <= 4)
     {
         switch (automataID)
         {
             case 0: crystal = new Crystal(crystalMatrix, 286); break;
             case 1: crystal = new Crystal(crystalMatrix, 324); break;
             case 2: crystal = new Crystal(crystalMatrix, 465); break;
             case 3: crystal = new Crystal(crystalMatrix, 501); break;
             case 4: crystal = new Crystal(crystalMatrix, 471); break;
         }
         IterateAutomata(crystal.GrowToNextIteration, iterationCount);
         SaveMatrixAsImage(crystalMatrix);
     }
     else
     {
         string ruleDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Rules\");
         TurmitRule turmiteRule = new TurmitRule();
         switch (automataID)
         {
             case 5: turmiteRule.ReadRuleFromFile(Path.Combine(ruleDir, @"Labirint.txt")); break;
             case 6: turmiteRule.ReadRuleFromFile(Path.Combine(ruleDir, @"Island.txt")); break;
             case 7: turmiteRule.ReadRuleFromFile(Path.Combine(ruleDir, @"Cross.txt")); break;
             default: turmiteRule.ReadRuleFromFile(Path.Combine(ruleDir, @"YellowSquare.txt")); break;
         }
         turmite = new Turmit(turmiteRule, turmiteMatrix);
         IterateAutomata(turmite.Move, iterationCount);
         SaveMatrixAsImage(turmiteMatrix);
     }
     Console.ReadLine();
 }
 static void SaveMatrixAsImage(CrystalMapping matrix)
 {
     Bitmap bitmap = new Bitmap(matrix.GetLength(), matrix.GetLength());
     for (int i = 0; i < matrix.GetLength(); i++)
         for (int k = 0; k < matrix.GetLength(); k++)
         {
             if (matrix.GetCellColor(i, k) == 1)
                 bitmap.SetPixel(i, k, Color.White);
             else
                 bitmap.SetPixel(i, k, Color.Black);
         }
     Console.WriteLine(GetNewImageFileName());
     bitmap.Save(GetNewImageFileName(),System.Drawing.Imaging.ImageFormat.Bmp);
 }
        private void Form1_Load(object sender, EventArgs e)
        {
            crystalMatrix = new CrystalMapping(MATRIX_RANGE);
            turmiteMatrix = new TurmiteMatrix(MATRIX_RANGE);
            turmiteRule = new TurmitRule();
            canvas = automataPictureBox.CreateGraphics();
            automataType.SetSelected(0, true);

            this.closure = new Action<bool>((bool flag) =>
            {
                this.Invoke(new Action(() =>
                {
                    automataType.Enabled = flag;
                    automataName.Enabled = flag;
                    startIterationBtn.Enabled = flag;
                }));
            });
        }
 private void DrawMatrix(CrystalMapping matrix)
 {
     SolidBrush myBrush = new SolidBrush(System.Drawing.Color.White);
     for (int i = 0; i < matrix.GetLength(); i++)
     {
         for (int k = 0; k < matrix.GetLength(); k++)
         {
             if (matrix.GetCellColor(i, k) == 1)
                 canvas.FillRectangle(myBrush, new Rectangle(i * SCALE, k * SCALE, SCALE, SCALE));
         }
     }
     myBrush.Dispose();
 }