最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

c# 實現(xiàn)雪花分形的示例

 更新時間:2020年10月20日 11:15:13   作者:黑衫老腰  
這篇文章主要介紹了c# 實現(xiàn)雪花分形的示例,幫助大家更好的利用c#繪制圖像,感興趣的朋友可以了解下

C#都沒人用了嗎,網(wǎng)上想找個現(xiàn)成的雪花分形代碼,都沒找見,有C++,有python,有java的,就沒有C#的,自己試試寫一個吧。

public partial class Form1 : Form
 {
  public Form1()
  {
   InitializeComponent();
  }

  private void Form1_Paint(object sender, PaintEventArgs e)
  {
   DrawKochSnow(e.Graphics);
  }

  private void ZheXian(Point p1, Point p2, Graphics g) // 4條基本線段組成的折線
  {
   Point p3 = new Point(p1.X + (p2.X - p1.X) / 3, p1.Y + (p2.Y - p1.Y) / 3); // 三等分點坐標
   Point p4 = new Point(p1.X + (p2.X - p1.X) * 2 / 3, p1.Y + (p2.Y - p1.Y) * 2 / 3); // 三等分點坐標
   Point p4XD3 = new Point(p4.X - p3.X, p4.Y - p3.Y); // p4相對于p3點的坐標
   //int x = (int)(p4XD3.X * Math.Cos(Math.PI / 3) - p4XD3.Y * Math.Sin(Math.PI / 3));
   //int y = (int)(p4XD3.X * Math.Sin(Math.PI / 3) + p4XD3.Y * Math.Cos(Math.PI / 3));
   // 注意計算機的屏幕垂直坐標和數(shù)學上相反,所以數(shù)學上逆時針旋轉在計算機上相當于順時針旋轉
   int x = (int)Math.Round(p4XD3.X * Math.Cos(Math.PI / 3) + p4XD3.Y * Math.Sin(Math.PI / 3));
   int y = (int)Math.Round(p4XD3.Y * Math.Cos(Math.PI / 3) - p4XD3.X * Math.Sin(Math.PI / 3));
   Point p5XD3 = new Point(x, y); // 凸起點p5相對于p3點的坐標
   Point p5 = new Point(p3.X + x, p3.Y + y); // p5相對于原點的坐標
   Pen pen = new Pen(Brushes.Black, 1);
   double length = Math.Sqrt(Math.Pow(p2.X - p1.X, 2) + Math.Pow(p2.Y - p1.Y, 2)) / 3;
   //Console.WriteLine(length);
   if (length > 20) // 通過最終線段長度可以控制迭代
   {
    ZheXian(p1, p3, g);
    ZheXian(p3, p5, g);
    ZheXian(p5, p4, g);
    ZheXian(p4, p2, g);
   }
   else
   {
    g.DrawLine(pen, p1, p3);
    g.DrawLine(pen, p3, p5);
    g.DrawLine(pen, p5, p4);
    g.DrawLine(pen, p4, p2);
   }
  }

  private void DrawKochSnow(Graphics g) // 科赫雪花(瑞典人科赫于1904年提出了著名的“雪花”曲線)
  {
   int length = 480;
   Point origin = new Point(this.ClientSize.Width / 2, this.ClientSize.Height / 2);
   g.FillEllipse(Brushes.Blue, new RectangleF(origin, new Size(10, 10)));
   // 計算三角形的頂點讓其中心和窗體的中心重合
   Point A = new Point(origin.X - length / 2, (int)(origin.Y + length / (2 * Math.Sqrt(3))));
   Point B = new Point(origin.X, (int)(origin.Y - length / Math.Sqrt(3)));
   Point C = new Point(origin.X + length / 2, (int)(origin.Y + length / (2 * Math.Sqrt(3))));
   ZheXian(A, B, g);
   ZheXian(B, C, g);
   ZheXian(C, A, g);
  }
 }

以上就是c# 實現(xiàn)雪花分形的示例的詳細內容,更多關于c# 雪花分形的資料請關注腳本之家其它相關文章!

相關文章

最新評論

新竹市| 忻州市| 临江市| 阿尔山市| 山阳县| 阜新市| 大名县| 仪陇县| 宜兴市| 天等县| 绵阳市| 视频| 济南市| 贵州省| 博乐市| 固原市| 木里| 尼勒克县| 鄂托克前旗| 濮阳县| 咸丰县| 北海市| 麻城市| 吉林市| 浑源县| 浪卡子县| 麻江县| 嘉定区| 高平市| 瓦房店市| 临清市| 玛纳斯县| 尤溪县| 望谟县| 尼木县| 余干县| 藁城市| 广灵县| 九台市| 庆云县| 鹤峰县|