while+for+swith用文本打印MandelBrot图像(C# 实现)

while+for+swith用文本打印MandelBrot图像(C# 实现)_第1张图片

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            double realCoord, imageCoord;
            double realTemp, imageTemp, realTemp2, arq;
            int iterations;
            for (imageCoord = 1.2; imageCoord >= -1.2; imageCoord -= 0.05)
            {
                for (realCoord = -0.6; realCoord <= 1.77; realCoord += 0.03)
                {
                    iterations = 0;
                    realTemp = realCoord;
                    imageTemp = imageCoord;
                    arq = (realCoord * imageCoord) + (imageCoord * imageCoord);
                    while ((arq < 4) && (iterations < 40))
                    {
                        realTemp2 = (realTemp * realTemp) - (imageTemp * imageTemp)
                                  - realCoord;
                        imageTemp = (2 * realTemp * imageTemp) - imageCoord;
                        realTemp = realTemp2;
                        arq = (realTemp * realTemp) + (imageTemp * imageTemp);
                        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");
            }
            
        }
    }
}


你可能感兴趣的:(while+for+swith用文本打印MandelBrot图像(C# 实现))