Quantcast
Channel: C#タグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 9707

cscの作法 その52

$
0
0
概要 cscの作法、調べてみた。 シェルピンスキーのギャスケットやってみた。 参考にしたページ 写真 サンプルコード using System; using System.Windows.Forms; using System.Drawing; class form1: Form { private int maxLevel = 6; form1() { BackColor = Color.Black; this.Text = "シェルピンスキーのギャスケット"; ClientSize = new Size(700, 500); } protected override void OnPaint(PaintEventArgs e) { DrawSierpinskiGasket(e.Graphics, 319, 40, 30, 430, 609, 430, 0); base.OnPaint(e); } private void DrawSierpinskiGasket(Graphics g, int x1, int y1, int x2, int y2, int x3, int y3, int level) { if (level == maxLevel) { g.DrawLine(Pens.Lime, x1, y1, x2, y2); g.DrawLine(Pens.Lime, x2, y2, x3, y3); g.DrawLine(Pens.Lime, x3, y3, x1, y1); } else { int xx1 = (int)((x1 + x2) / 2.0); int yy1 = (int)((y1 + y2) / 2.0); int xx2 = (int)((x2 + x3) / 2.0); int yy2 = (int)((y2 + y3) / 2.0); int xx3 = (int)((x3 + x1) / 2.0); int yy3 = (int)((y3 + y1) / 2.0); DrawSierpinskiGasket(g, x1, y1, xx1, yy1, xx3, yy3, level + 1); DrawSierpinskiGasket(g, x2, y2, xx1, yy1, xx2, yy2, level + 1); DrawSierpinskiGasket(g, x3, y3, xx3, yy3, xx2, yy2, level + 1); } } [STAThread] public static void Main() { Application.Run(new form1()); } } 以上。

Viewing all articles
Browse latest Browse all 9707

Trending Articles