예제 #1
0
        private void iterate(object sender = null, RoutedEventArgs e = null)
        {
            lock (activeLifeMatrix)
            {
                activeLifeMatrix.Iterate();
            }
            Action updateAction = updateDisplay;

            this.Dispatcher.Invoke(updateDisplay);
        }
예제 #2
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            _lifeMatrices = new ObservableCollection <LifeMatrix>();
            LifeMatrix matrix1 = new StandardLife(20);

            matrix1.Randomize();
            _lifeMatrices.Add(matrix1);
            LifeMatrix matrix2 = new RedBlueLife(20);

            _lifeMatrices.Add(matrix2);
            matrix2.Randomize();
            LifeMatrix matrix3 = new GeneticLife(20);

            matrix3.Randomize();
            _lifeMatrices.Add(matrix3);

            activeLifeMatrix     = matrix2;
            typesBox.DataContext = _lifeMatrices;

            matrix.RowDefinitions.Clear();

            for (int rowIndex = 0; rowIndex < activeLifeMatrix.Size; rowIndex++)
            {
                RowDefinition rowDef = new RowDefinition();
                rowDef.Height = new GridLength((int)(matrix.ActualHeight / activeLifeMatrix.Size));
                matrix.RowDefinitions.Add(rowDef);
            }
            matrix.ColumnDefinitions.Clear();
            for (int columnIndex = 0; columnIndex < activeLifeMatrix.Size; columnIndex++)
            {
                ColumnDefinition colDef = null;
                colDef       = new ColumnDefinition();
                colDef.Width = new GridLength(matrix.ActualWidth / activeLifeMatrix.Size);
                matrix.ColumnDefinitions.Add(colDef);
            }

            activeLifeMatrix.Iterate();
            updateDisplay();
        }