首页 > 代码库 > Mandelbrot图像

Mandelbrot图像

 

图片

 图片

 

 

 

 using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            double realcoord, imagcoord;
            double realtemp, imagtemp, realtemp2, arg;
            int iterations;
            for (imagcoord = 1.2; imagcoord >= -1.2; imagcoord -= 0.05)
            {
                for (realcoord = -0.6; realcoord <= 1.77; realcoord += 0.03)
                {
                    iterations = 0;
                    realtemp = realcoord;
                    imagtemp = imagcoord;
                    arg = (realcoord * realcoord) + (imagcoord * imagcoord);
                    while ((arg < 4) && (iterations < 40))
                    {
                        realtemp2 = (realtemp * realtemp) - (imagtemp * imagtemp) - realcoord;
                        imagtemp = (2 * realtemp * imagtemp) - imagcoord;
                        realtemp = realtemp2;
                        arg = (imagtemp * imagtemp) + (realtemp * realtemp);
                        iterations += 1;
                    }
                    switch (iterations % 4)
                    {
                        case 0:
                            Console.Write(".");
                            break;
                        case 1:
                            Console.Write("o");
                            break;
                        case 2:
                            Console.Write("O");
                            break;
                        case 3:
                            Console.Write("@");
                            break;
                    }
                }
                Console.Write("\n");
            }
            Console.ReadKey();

         }
    }
}