protected void FastForward() { lock (this) { Clear(); for (int i = 0; i < 100; i++) { automata.Iterate(); } } }
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(); }