star

搜索

RSS

RSS Link

计数器

139723

曼德勃罗特集

2010年8月12日 02:44 | Comments(1558) | Category:C语言 | Tags:

#include <stdio.h>

int main(void)
{
	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;
			
			for(; arg<4 && iterations<40; ++iterations)
			{
				realTemp2 = realTemp*realTemp - imagTemp*imagTemp - realCoord;
				imagTemp  = 2*realTemp*imagTemp - imagCoord;
				realTemp  = realTemp2;
				arg       = realTemp*realTemp + imagTemp*imagTemp;	
			}
			
			switch (iterations % 4)
			{
				case 0: putchar('.'); break;
				case 1: putchar('o'); break;
				case 2: putchar('O'); break;
				case 3: putchar('@'); break;
			}
		}
		putchar(10);
	}
	return 0;
}