การเขียน Fractal ใน C# 
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Paint(object sender, PaintEventArgs e)
{
DrawFractal(e.Graphics, 300, 10, 1,1);
DrawFractal(e.Graphics, 900, 10, 1,2);
DrawFractal(e.Graphics, 1500, 10, 1,3);

DrawFractal(e.Graphics, 300, 530, 1,4);
DrawFractal(e.Graphics, 900, 530, 1,6);
DrawFractal(e.Graphics, 1500, 530, 1,8);
}

int size = 270;

public void DrawFractal(Graphics g,int x,int y ,int n,int N )
{

if(n == Math.Pow(2,N))
{

g.DrawLine(Pens.Black ,x, y, (int)(x - size / n), (int)(y + Math.Sqrt(3) * size / n));
g.DrawLine(Pens.Black, x, y, (int)(x + size / n), (int)(y + Math.Sqrt(3) * size / n));
g.DrawLine(Pens.Black, (int)(x + size / n), (int)(y + Math.Sqrt(3) * size / n), (int)(x - size / n), (int)(y + Math.Sqrt(3) * size / n));
return;
}

DrawFractal( g, x, y ,n*2,N);
DrawFractal( g, (int)(x - size / n /2 ), (int)(y + Math.Sqrt(3)*size / n / 2) ,n*2,N);
DrawFractal( g, (int)(x + size / n / 2 ), (int)(y + Math.Sqrt(3)*size / n / 2) ,n*2,N);

}
}





[ view entry ] ( 27142 views )   |  permalink  |  $star_image$star_image$star_image$star_image$star_image ( 3 / 2587 )

| 1 | 2 | 3 | 4 | 5 | Next> Last>>