1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
public static void MandelBrotFractal()
{
double x1 =-2.1;
double x2 =0.6;
double y1 =-1.2;
double y2 = 1.2;
int zoom = 100;
int iteration_max = 50;
double image_x =(x2-x1)*zoom;
double image_y =(y2-y1)*zoom;
if (!Directory.Exists("c:\\Fractal"))
{
Directory.CreateDirectory("c:\\Fractal");
}
if (File.Exists("c:\\Fractal\\MandelBrotFractal.bmp"))
{
File.Delete("c:\\Fractal\\MandelBrotFractal.bmp");
}
Bitmap img = new Bitmap((int)image_x, (int)image_y);
img.MakeTransparent(Color.Black);
Graphics bufferGfx = Graphics.FromImage(img);
bufferGfx.Clear(Color.FromArgb(255, 255, 255)); //remplis le bitmap d'un fond blanc
DateTime start = DateTime.Now;
for (int x = 0; x < image_x; x++)
{
for (int y = 0; y < image_y; y++)
{
double c_r = x / (zoom + x1);
double c_i = y / (zoom + y1);
double z_r = 0;
double z_i = 0;
int i = 0;
do
{
double tmp = z_r;
z_r = (z_r * z_r) - (z_i * z_i) + c_r;
z_i = (2 * tmp * z_i) + c_i;
i++;
}while((z_r*z_r)+(z_i*z_i)<4 && i<iteration_max);
if (i == iteration_max)
{
img.SetPixel(x, y, Color.Red);
}
}
}
TimeSpan totalTime = start - DateTime.Now;
Console.WriteLine(totalTime);
img.Save("c:\\Fractal\\MandelBrotFractal.bmp");
} |
Partager