Example #1
0
 protected void RestartOld()
 {
     Clear();
     lock (this)
     {
         automata.Initialize();
     }
 }
Example #2
0
        protected void RestartWithNew()
        {
            lock (this)
            {
                Clear();
                rule     = new RandomLangtonRule(numStates, lambda);
                automata = new BasicCellularAutomata(fieldSize, numStates, rule);

                automata.Initialize();
            }
        }
Example #3
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            visual = new DrawingVisual();

            this.AddVisualChild(visual);

            rule     = new RandomLangtonRule(numStates, lambda);
            automata = new BasicCellularAutomata(fieldSize, numStates, rule);

            automata.Initialize();

            Draw(automata.GetField());

            Task task = new Task(() =>
            {
                while (true)
                {
                    Dispatcher.Invoke(() => {
                        switch (keyPressed)
                        {
                        case Key.Left:
                            RestartOld();
                            break;

                        case Key.Right:
                            RestartWithNew();
                            break;

                        case Key.Space:
                            FastForward();
                            break;

                        default:
                            Draw(automata.GetField());
                            break;
                        }

                        keyPressed = Key.None;
                    });

                    lock (this)
                    {
                        automata.Iterate();
                    }

                    System.Threading.Thread.Sleep(100);
                }
            });

            task.Start();
        }