public CellularAutomataCanvas() { InitializeComponent(); automataSpace.AllowDrop = true; this.DoubleBuffered = true; speedControl.Minimum = 1; speedControl.Maximum = 500; speedControl.LargeChange = 100; speedControl.SmallChange = 10; speedControl.Value = 200; speedControl.AutoToolTip = true; speedControl.TrackBar.TickFrequency = 50; speedControl.ToolTipText = string.Format("{0}ms", speedControl.Value); speedValueLabel.Text = speedControl.ToolTipText; _display = new Monitor(10); Size trueSize = automataSpace.ClientSize; trueSize.Height /= _display.Ratio; trueSize.Width /= _display.Ratio; //_environment = new CAEnvironment(trueSize, false, "CellularAutomation", "BaseAutomation", new object[] { (byte) 1 }); _environment = new CAEnvironment(trueSize, false, "GameOfLife", "Moore", null); AttachEvents(); }
/// <summary> /// Creates a new <see cref="Cell"/> instance using its location and state from an environment. /// </summary> /// <param name="location">The location of the state to be created.</param> /// <param name="environment">It is used to get the <see cref="Cell"/>`s state.</param> /// <returns>The initialized <see cref="Cell"/> object.</returns> public static Cell Create(Point location, CAEnvironment environment) { var c = new Cell(location); var key = c.GetKey(); if (environment.States.Contains(key)) { c.State = true; } return c; }
public CellCollection GetNeighbours(Point location, CAEnvironment environment) { Cell c = environment.GetCell(location); CellCollection neighbours = new CellCollection(); Point newPoint = location; for (int i = 0; i < _neighboursDelta.Length / 2; i++) { newPoint.Offset(_neighboursDelta[i, 0], _neighboursDelta[i, 1]); neighbours.Add(environment.GetCell(newPoint)); newPoint = location; } return neighbours; }
public void DrawAutomata(object[] args, CAEnvironment environment) { Graphics graphics = (Graphics)args[0]; Brush brush = (Brush)args[1]; int maxWidth = environment.Size.Width * Ratio; int maxHeight = environment.Size.Height * Ratio; Bitmap BackBuffer = new Bitmap(maxWidth, maxHeight); Graphics drawingArea = Graphics.FromImage(BackBuffer); environment.Prepair(); IEnumerator enumerator = environment.GetEnumerator(); Point cell; while (enumerator.MoveNext()) { cell = Utilities.GetCellFromKey((long) enumerator.Current); drawingArea.FillRectangle(brush, Ratio * cell.X, Ratio * cell.Y, Ratio, Ratio); } graphics.DrawImageUnscaled(BackBuffer, 0, 0); BackBuffer.Dispose(); }
public void DrawGuides(object[] args, CAEnvironment environment) { Graphics g = (Graphics)args[0]; g.DrawImageUnscaled(gridBitmap, 0, 0); }