七夕节特辑-简单心形程序

1.蓝绿相间的心形。

#include
#include
#include 
using namespace std;
int main()
{
	float x, y;
	for (y = 1.5f; y >-1.5f; y -= 0.1f)
	{
		for (x = -1.5f; x <1.5f; x += 0.05f)
		{
			float a = x*x + y*y - 1;
			if ((a*a*a- x*x*y*y*y)<=0)
				cout<<'*';//心形方程
			else
				cout<<" ";
		}
		cout<

2. 红色跳动的心。

#include 
#include 
#include 
#include 

float f(float x, float y, float z)
{
	float a = x * x + 9.0f / 4.0f * y * y + z * z - 1;
	return a * a * a - x * x * z * z * z - 9.0f / 80.0f * y * y * z * z * z;
}

float h(float x, float z)
{
	for (float y = 1.0f; y >= 0.0f; y -= 0.001f)
		if (f(x, y, z) <= 0.0f)
			return y;
	return 0.0f;
}

int main()
{
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),0x0C);
	HANDLE o = GetStdHandle(STD_OUTPUT_HANDLE);
	_TCHAR buffer[25][80] = { _T(' ') };
	_TCHAR ramp[] = _T(".:-=+*#%@");
	int count= 0;
	int count1=0;
	//system("color F4");
	for (float t = 0.0f;; t += 0.1f)
	{
		int sy = 0;
		float s = sinf(t);
		float a = s * s * s * s * 0.2f;

		for (float z = 1.3f; z > -1.2f; z -= 0.1f)
		{
			_TCHAR* p = &buffer[sy++][0];
			float tz = z * (1.2f - a);
			for (float x = -1.5f; x < 1.5f; x += 0.05f)
			{
				float tx = x * (1.2f + a);
				float v = f(tx, 0.0f, tz);
				if (v <= 0.0f)
				{
					float y0 = h(tx, tz);
					float ny = 0.01f;
					float nx = h(tx + ny, tz) - y0;
					float nz = h(tx, tz + ny) - y0;
					float nd = 1.0f / sqrtf(nx * nx + ny * ny + nz * nz);
					float d = (nx + ny - nz) * nd * 0.5f + 0.5f;
					*p++ = ramp[(int)(d * 5.0f)];
				}
				else
					*p++ = ' ';
			}
		}

		for (sy = 0; sy < 25; sy++)
		{
			COORD coord = { 0, sy };
			SetConsoleCursorPosition(o, coord);
			WriteConsole(o, buffer[sy], 79, NULL, 0);
		}
		if(count <= 10)
		{
			printf("I Love You ———.Mua~\n") ;//表白内容
			printf("         By Myname");// 表白者的名字
			count++;
		}
		else
		{
			printf("You Are My Best Lover.\n");
			printf("            ++++++");
			count++;
			if(count>=20)
			{
				count =0;
			}
		}
		Sleep(33);
	}
}

3.逐行显示,然后显示蓝绿闪烁心形图案。

#include 
#include 
#include 
using namespace std;
int main()
{ 
	system("color 0a");//亮绿色 
	float x, y, i, e=1, a;
	goto end; 
	for (y = 1.5f; y >-1.5f; y -= 0.1f)
	{
		i++;
		for (x = -1.5f; x <1.5f; x += 0.05f)
		{
			a = x*x + y*y - 1;
			if ((a*a*a- x*x*y*y*y)<=0)//心形方程
				cout << '*';
			else
				cout << " ";
		}
		Sleep(300);//逐间隔时间
		system("cls");//清屏
		for(e=1; e<=i; e++) 
			cout << endl;//每次多打一个空行
	}
	HANDLE hout;
	COORD coord;
	coord.X=0;
	coord.Y=0;
	hout=GetStdHandle(STD_OUTPUT_HANDLE);//让光标回到文件开头
	SetConsoleCursorPosition(hout,coord);
	system("color 09");//亮蓝色 
	end:
	for (y = 1.5f; y >-1.5f; y -= 0.1f)
	{
		for (x = -1.5f; x <1.5f; x += 0.05f)
		{
			a = x*x + y*y - 1;
			if ((a*a*a- x*x*y*y*y)<=0)//心形方程
				cout << '*';
			else
				cout << " ";
		}
		cout << endl;
		Sleep(400);//设置间隔时间

	}
	/*
	//暗色
	system("color 01"),Sleep(500);//蓝色
	system("color 02"),Sleep(500);//绿色
	system("color 03"),Sleep(500);//湖蓝色
	system("color 04"),Sleep(500);//红色
	system("color 05"),Sleep(500);//紫色
	system("color 06"),Sleep(500);//黄色
	system("color 07"),Sleep(500);//白色
	system("color 08"),Sleep(500);// 灰色
	//以下为亮色
	system("color 09"),Sleep(500);// 蓝
	system("color 0a"),Sleep(500);//绿
	system("color 0b"),Sleep(500);//淡浅绿
	system("color 0c"),Sleep(500);//淡红
	system("color 0d"),Sleep(500);//淡紫
	system("color 0e"),Sleep(500);//淡黄
	system("color 0f"),Sleep(500);//亮白
	*/
	
	while(1)
	{
	//	system("color 01");
	//	Sleep(600);
	//	system("color 09");
	//	Sleep(600);//蓝色闪烁
	//	system("color 04");
	//	Sleep(600);
		system("color 0c");
		Sleep(600);//红色闪烁
		//system("color 02");//绿色
	//	Sleep(600);
		system("color 0a");//绿
		Sleep(600);
	}//蓝红循环闪烁灯
	//
	return 0;
}

 

你可能感兴趣的:(七夕节特辑-简单心形程序)