private void splitBtn_Click(object sender, EventArgs e) { //var points = ToDoubleList(Points); //var holes = new List<int>(); //var indices = Earcut.Tessellate(points, holes); //Drawing.Clear(); //for (int i = 0; i < indices.Count; i += 3) //{ // Point a = Points[indices[i]]; // Point b = Points[indices[i + 1]]; // Point c = Points[indices[i + 2]]; // Drawing.LineBresenham(a, b, Color.Black); // Drawing.LineBresenham(b, c, Color.Black); // Drawing.LineBresenham(c, a, Color.Black); //} //drawBox.Image = Drawing.Canvas; var points = Points.Select <Point, PointF>(i => i).ToList(); if (Triangulate.Process(points, out List <Point> result)) { int count = result.Count / 3; Drawing.Clear(); for (int i = 0; i < count; i++) { var p1 = result[i * 3 + 0]; var p2 = result[i * 3 + 1]; var p3 = result[i * 3 + 2]; Drawing.LineBresenham(p1, p2, Color.Black); Drawing.LineBresenham(p2, p3, Color.Black); Drawing.LineBresenham(p3, p1, Color.Black); } drawBox.Image = Drawing.Canvas; } }
private void Form1_KeyDown(object sender, KeyEventArgs e) { int centY = Center.Y; int centX = Center.X; int angle = 0, distance = 0; if (e.KeyCode == Keys.Q) { angle = 360; distance = -1; } else if (e.KeyCode == Keys.E) { angle = 361; distance = 1; } else { return; } if ((X.Count >= 3) && (Y.Count >= 3)) { Drawing.LineBresenham( new Point(X[X.Count - 1], Y[Y.Count - 1]), new Point(X[0], Y[0]), Color.Black); while (true) { for (int i = 0; i < X.Count; i++) { X_[i] = (int)(centX + ((X[i] - centX) * Math.Cos(angle * Math.PI / 180) - (Y[i] - centY) * Math.Sin(angle * Math.PI / 180))); Y_[i] = (int)(centY + ((X[i] - centX) * Math.Sin(angle * Math.PI / 180) + (Y[i] - centY) * Math.Cos(angle * Math.PI / 180))); } for (int i = 0; i < X.Count - 1; i++) { Drawing.LineBresenham( new Point(X_[i], Y_[i]), new Point(X_[i + 1], Y_[i + 1]), Color.Black); } Drawing.LineBresenham( new Point(X_[X_.Count - 1], Y_[Y_.Count - 1]), new Point(X_[0], Y_[0]), Color.Black); angle += distance; label1.Text = $"Degrees: {angle}"; Thread.Sleep(50); drawBox.Refresh(); if (angle % 360 == 0) { return; } else { drawBox.Image = Drawing.Clear(); } } } }
void ClearButtonClick(object sender, EventArgs e) { drawBox.Image = BobRoss.Clear(); }