十年網(wǎng)站開發(fā)經(jīng)驗 + 多家企業(yè)客戶 + 靠譜的建站團隊
量身定制 + 運營維護+專業(yè)推廣+無憂售后,網(wǎng)站問題一站解決
如何使用WPF實現(xiàn)一個平面三角形3D運動效果?針對這個問題,這篇文章詳細介紹了相對應的分析和解答,希望可以幫助更多想解決這個問題的小伙伴找到更簡單易行的方法。
實現(xiàn)效果如下:
思路:封裝三角形三個頂點和路徑的三角形類,圖形渲染時同步更新公共頂點三角形的頂點位置。
步驟:
1、三角形類Triangle.cs
public Point A, B, C;//初始三個頂點 public Point VA, VB, VC;//運動的三個頂點 public Path trianglePath;//三角形路徑 public Color triangleColor;//填充 public double ColorIndex;//顏色深度 public Triangle(Point a, Point b, Point c, Color co, double z) { A = VA = a; B = VB = b; C = VC = c; triangleColor = co; ColorIndex = z; trianglePath = new Path(); Draw(); } ////// 繪制三角形 /// public void Draw() { var g = new StreamGeometry(); using (StreamGeometryContext context = g.Open()) { context.BeginFigure(VA, true, true); context.LineTo(VB, true, false); context.LineTo(VC, true, false); } trianglePath.Data = g; trianglePath.Fill = new SolidColorBrush(triangleColor); }