/// <summary> /// Berechnet die kleine Vorschau einer Zelle. /// </summary> /// <param name="x">horizontale Achse</param> /// <param name="y">vertikale Achse</param> public BitmapSource DrawPreview(int col, int row, int targetDimension) { DominoCell cell = cells[col, row]; float scaling_factor = PreviewScaleFactor(targetDimension); // scale everything to the same size Bitmap b = new Bitmap((int)(cell.width * scaling_factor + 2), (int)(cell.height * scaling_factor + 2)); // +2 for right borders Graphics g = Graphics.FromImage(b); for (int colc = (col == 2) ? 1 : 0; colc <= ((col == 0) ? 1 : 2); colc++) { for (int rowc = (row == 2) ? 1 : 0; rowc <= ((row == 0) ? 1 : 2); rowc++) // only use the cells next to the specified (so top left uses 4 top center, center left and center center). { DominoCell current = cells[colc, rowc]; int xOffsetMultiplier = colc - col; // for moving the cells int yOffsetMultiplier = rowc - row; for (int i = 0; i < current.Dominoes.Length; i++) { DominoDefinition transformed = current.Dominoes[i].TransformDefinition( xOffsetMultiplier * ((xOffsetMultiplier > 0) ? cell.width : current.width), yOffsetMultiplier * ((yOffsetMultiplier > 0) ? cell.height : current.height), 0, 0, 0, 0); // move the dominoes RectangleF container = transformed.GetContainer(); // get containing rectangle if (container.X >= cells[col, row].width || container.X + container.Width <= 0 || container.Y >= cells[col, row].height || container.Y + container.Height <= 0) { continue; // check if rectangle is out of drawing area } g.FillPath(Brushes.LightGray, transformed.GetPath(scaling_factor)); g.DrawPath(new Pen(Color.Black, 2 * scaling_factor), transformed.GetPath(scaling_factor)); } } } return(ImageHelper.BitmapToBitmapImage(b)); }
public GenStructHelper GenerateCircle() { List <DominoDefinition> dominos = new List <DominoDefinition>(); int circlecount = 0; int diameter = d_min; while (circlecount < circles) { diameter += 2 * domino_height + 2 * normal_distance; // get number of dominoes in this spiral double domino_angle = Math.Asin((double)domino_width / diameter) * 2; double distance_angle = Math.Asin((double)tangential_distance / diameter) * 2; int current_domino_count = (int)Math.Floor(2 * Math.PI / ((double)domino_angle + distance_angle)); // equally space the distance between all dominoes distance_angle = (2 * Math.PI - (domino_angle * current_domino_count)) / current_domino_count; // calculate dominoes double angle = 0; for (int i = 0; i < current_domino_count; i++) { DominoDefinition d = GenerateDomino(diameter, angle, domino_angle); angle += domino_angle + distance_angle; dominos.Add(d); } circlecount++; } DominoDefinition[] Domino = dominos.ToArray(); float x_min = int.MaxValue; float y_min = int.MaxValue; float x_max = int.MinValue; float y_max = int.MinValue; foreach (DominoDefinition d in Domino) { RectangleF container = d.GetContainer(); if (container.X < x_min) { x_min = container.X; } if (container.Y < y_min) { y_min = container.Y; } if (container.X + container.Width > x_max) { x_max = container.X + container.Width; } if (container.Y + container.Height > y_max) { y_max = container.Y + container.Height; } } for (int i = 0; i < Domino.Length; i++) { Domino[i] = Domino[i].TransformDefinition(-x_min, -y_min, 0, 0, 0, 0); } GenStructHelper g = new GenStructHelper(); g.HasProtocolDefinition = false; g.dominoes = Domino; g.width = x_max - x_min; g.height = y_max - y_min; return(g); GenStructHelper circle = new GenStructHelper(); // do some magic return(circle); }
public GenStructHelper GenerateSpiral() { List <DominoDefinition> dominolist = new List <DominoDefinition>(); double theta = theta_min; int ycounter = 0; while (theta < theta_max) { DominoDefinition d = CreateDomino(theta); d.ProtocolDefinition = new DominoProtocolDefinition(); d.ProtocolDefinition.yParams.yConstant = (int)Math.Floor((theta - theta_min) / (2d * Math.PI)); d.ProtocolDefinition.xParams.xConstant = ycounter; dominolist.Add(d); double start_value = theta + 0.01d; double theta_new = newton_archimedean(theta, start_value, (double)tangential_distance + (double)domino_width); while (theta_new < theta) { start_value += 0.01d; theta_new = newton_archimedean(theta, start_value, (double)tangential_distance + (double)domino_width); } ycounter++; if ((int)Math.Floor((theta - theta_min) / (2d * Math.PI)) != (int)Math.Floor((theta_new - theta_min) / (2d * Math.PI))) { ycounter = 0; } theta = theta_new; } DominoDefinition[] Domino = dominolist.ToArray(); float x_min = int.MaxValue; float y_min = int.MaxValue; float x_max = int.MinValue; float y_max = int.MinValue; foreach (DominoDefinition d in Domino) { RectangleF container = d.GetContainer(); if (container.X < x_min) { x_min = container.X; } if (container.Y < y_min) { y_min = container.Y; } if (container.X + container.Width > x_max) { x_max = container.X + container.Width; } if (container.Y + container.Height > y_max) { y_max = container.Y + container.Height; } } for (int i = 0; i < Domino.Length; i++) { Domino[i] = Domino[i].TransformDefinition(-x_min, -y_min, 0, 0, 0, 0); } GenStructHelper g = new GenStructHelper(); g.HasProtocolDefinition = true; g.dominoes = Domino; g.width = x_max - x_min; g.height = y_max - y_min; return(g); }