public CAGraphCell(CAGraph parent, ValueTuple <ushort, ushort, ushort> position, Dictionary <string, dynamic> properties, CAGraphCellAgent agent) : base(CAEntityType.Cell, properties) { this.Parent = parent; this.Position = position; if (agent != null) { this.Agent = agent.Copy(this); } }
//public static T GetTypedValue<T>(CAProperty property) //{ // dynamic value = property.value; // return value; //} public static Bitmap MakeImage(CA ca) { CAGraph graph = ca.Graph; CASettings settings = ca.Settings; // needs to be SVG that returns various types if (graph.Shape == GridShape.Square) { int x = graph.Cells.GetLength(0); int y = graph.Cells.GetLength(1); int z = graph.Cells.GetLength(2); Bitmap bmp = new Bitmap(x, y); using (Graphics g = Graphics.FromImage(bmp)) { for (ushort i = 0; i < z; i++) { Bitmap layer = new Bitmap(x, y); for (ushort j = 0; j < x; j++) { for (ushort k = 0; k < y; k++) { var cell = graph.GetCell(new ValueTuple <ushort, ushort, ushort>(j, k, i)); Color color = Color.Black; if (cell != null) { if (cell.ContainsAgent()) { int state = cell.Agent.GetStateProperty(); if (settings.StateColorMap.Count >= state) { color = settings.StateColorMap[state]; } } } layer.SetPixel(j, k, color); } } g.DrawImage(layer, new Point(0, 0)); } } return(bmp); } else { throw new Exception("Graph shape not expected."); } }
public CAGraph Copy(CA ca) { var graph = new CAGraph(ca, this.Dimensions, this.Shape, this.AgentCells, this.Cells, this.Properties); return(graph); }
public CAGraphCell Copy(CAGraph graph) { var cell = new CAGraphCell(graph, this.Position, this.Properties, this.Agent); return(cell); }
//private Tuple<ushort, ushort, ushort>[][] Neighbors { get; set; } //System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); public CAGraphCell(CAGraph parent, ValueTuple <ushort, ushort, ushort> position) : base(CAEntityType.Cell) { this.Parent = parent; this.Position = position; //this.Neighbors = new Tuple<ushort, ushort, ushort>[Enum.GetNames(typeof(CANeighborhoodType)).Count()][]; }