c语言心形告白

1.彩色告白
#include<stdio.h>
#include<math.h>
#include<windows.h>
#include<time.h>
#define U 0.1
#define V 0.053
void SetColor(unsigned short ForeColor,unsigned short BackGroundColor)
{
	HANDLE hCon=GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleTextAttribute(hCon,(ForeColor%16)|(BackGroundColor%16*16));
}
int main()
{
	int i,s=0,t,a=10,b=11,c=12,d=13,e=14;
	int z[] = {32,32,206,210,207,178,187,182,196,227,33,32,32};
	float x,y;
	srand(time(NULL));
	for(y=1.3;y>=-1.1;y-=U)
	{
		for(x=-2;x<1.4;x+=V)
		{
			if((((x*x+y*y-1)*(x*x+y*y-1)*(x*x+y*y-1)-x*x*y*y*y)<=0))
			{
				if(y>=1.3-10*U||y<=1.3-11*U)
				{
				s++;
				if(s%4==1){SetColor(a,0);printf("l");}
				if(s%4==2){SetColor(e,0);printf("o");}
				if(s%4==3){SetColor(c,0);printf("v");}
				if(s%4==0){SetColor(d,0);printf("e");}
				}
				else
				{	
					for(i = 0;i < 42;i++)
					{	
						if(i<=14||i>=28)
						{
							s++;
							if(s%4==1){SetColor(a,0);printf("l");}
							if(s%4==2){SetColor(e,0);printf("o");}
							if(s%4==3){SetColor(c,0);printf("v");}
							if(s%4==0){SetColor(d,0);printf("e");}
						}
						else
						{
							SetColor(b,0);
							printf("%c", z[i-15]);
							Sleep(50);
						}
					}
					break;
				}
			}
				else
					printf(" ");
					Sleep(1);
		}
	printf("\n");
	}
	printf("按任意键继续!");
	getchar();	
	while(1)
	{
				system("cls");
			t=a;a=b;b=c;c=d;d=e;e=t;
			for(y=1.3;y>=-1.1;y-=U)
		{
			for(x=-2;x<1.4;x+=V)
			{
				if((((x*x+y*y-1)*(x*x+y*y-1)*(x*x+y*y-1)-x*x*y*y*y)<=0))
				{
					if(y>=1.3-10*U||y<=1.3-11*U)
					{
					s++;
					if(s%4==1){SetColor(a,0);printf("l");}
					if(s%4==2){SetColor(b,0);printf("o");}
					if(s%4==3){SetColor(c,0);printf("v");}
					if(s%4==0){SetColor(d,0);printf("e");}
					}
					else
					{	
						for(i = 0;i < 42;i++)
						{	
							if(i<=14||i>=28)
							{
								s++;
								if(s%4==1){SetColor(a,0);printf("l");}
								if(s%4==2){SetColor(b,0);printf("o");}
								if(s%4==3){SetColor(c,0);printf("v");}
								if(s%4==0){SetColor(d,0);printf("e");}
							}
							else
							{
								SetColor(e,0);
								printf("%c", z[i-15]);
							}
						}
						break;
					}
				}
					else
						printf(" ");
			}
				printf("\n");
		}
			Sleep(1000);
			system("cls");
			
	}
}

2.简单心形
#include <math.h> 
#include <stdio.h>
int main()
{
float y, x, a;
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;
putchar(a*a*a - x*x*y*y*y <= 0.0f ? '*' : ' ');
}
putchar('\n');
}
return 0;
}

3.花纹心形
#include <math.h>
#include <stdio.h>
int main()
{
float y, x, z,f;
for (y = 1.5f;y > -1.5f;y -= 0.1f)
{
for (x = -1.5f;x < 1.5f;x += 0.05f)
{
z = x*x + y*y - 1;
f = z*z*z - x*x*y*y*y;
putchar(f <= 0.0f ? ".:-=+*#%@"[(int)(f*-8.0f)] : ' ');
}
putchar('\n');
}


getchar();
return 0;
}

4.跳动心形
#include <stdio.h>
#include <math.h>
#include <windows.h>
#include <tchar.h>

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() {
HANDLE o = GetStdHandle(STD_OUTPUT_HANDLE);
_TCHAR buffer[25][80] = { _T(' ') };
_TCHAR ramp[] = _T(".:-=+*#%@");

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);
}
Sleep(33);
}
}

5.心形小程序 
#include<stdio.h>
#include<math.h>
#include<windows.h>
#include<time.h>
#include<stdlib.h>
void SetColor(unsigned short ForeColor,unsigned short BackGroundColor)
{
	HANDLE hCon=GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleTextAttribute(hCon,(ForeColor%16)|(BackGroundColor%16*16));
}
int main()
{

	float x,y;
	int s=0,n,i,j;
		for(i = 1;i <= 50;i++)
	{
		SetColor(0,14);
		printf(" ");
		printf("%d%%",2*i);
		Sleep(101-2*i);
		printf("\b\b\b");
	}
	SetColor(15,0);
	printf("\b\n加载完成!即将进入:");
	Sleep(2000);
	system("cls");
	do
	{
		system("color 0E");
		for(i=0;i<=56;i++)
	{
		if(i>=20){printf("*");Sleep(10);}
		else printf(" ");
	}printf("\n");
	for(i=0;i<=56;i++)
	{
		if(i>=20){printf("*");Sleep(10);}
		else printf(" ");
	}
	printf("\n\t\t\t你想要怎样的心形:\n");
	printf("\n\t\t\t1:由love组成的心形!\n");
	printf("\n\t\t\t2:由随机字符组成的心形!\n");
	printf("\n\t\t\t3:由随机数字组成的心形!\n");
	printf("\n\t\t\t4:由随机颜色组成的心形!\n");
	printf("\n\t\t\t5:退出!\n");
	for(i=0;i<=56;i++)
	{
		if(i>=20){printf("*");Sleep(10);}
		else printf(" ");
	}printf("\n");
	for(i=0;i<=56;i++)
	{
		if(i>=20){printf("*");Sleep(10);}
		else printf(" ");
	}
	printf("\n\t\t\t");

	srand(time(NULL));
	scanf("%d",&n);
	system("cls");



		switch(n)
			{
		case 1:
	for(x=1.3;x>=-1.1;x-=0.1)
	{	for(y=-2;y<=1.4;y+=0.053)
		{
			if(pow(x*x+y*y-1,3)-x*x*x*y*y<=0)
			{
				s++;
				if(s%4==1)printf("l");
				if(s%4==2)printf("o");
				if(s%4==3)printf("v");
				if(s%4==0)printf("e");
				Sleep(2);
			}
			else
				printf(" ");
		}
	printf("\n");
	}
	printf("绘制完成,按任意键返回主页面!");break;




	case 2:	for(x=1.3;x>=-1.1;x-=0.1)
	{	for(y=-2;y<=1.4;y+=0.053)
		{
			if(pow(x*x+y*y-1,3)-x*x*x*y*y<=0)
			{
				printf("%c",rand()%10+rand()%10+97);
				Sleep(2);
			}
			else
				printf(" ");
		}
	printf("\n");
	}
	printf("绘制完成,按任意键返回主页面!");break;
		
	
	
	
	
	
	
	case 3:for(x=1.3;x>=-1.1;x-=0.1)
	{	for(y=-2;y<=1.4;y+=0.053)
		{
			if(pow(x*x+y*y-1,3)-x*x*x*y*y<=0)
			{
				printf("%d",rand()%10);
				Sleep(2);
			}
			else
				printf(" ");
		}
	printf("\n");
	}
	printf("绘制完成,按任意键返回主页面!");break;
		
		
		
		
		
		case 4:	for(x=1.3;x>=-1.1;x-=0.1)
	{	for(y=-2;y<=1.4;y+=0.053)
		{
			if(pow(x*x+y*y-1,3)-x*x*x*y*y<=0)
			{
				SetColor(0,rand()%6+10);
				printf(" ");
				Sleep(2);
			}
			else
			{SetColor(0,0);
			printf(" ");}
		}
	printf("\n");
	}
	SetColor(15,0);
	printf("绘制完成,按任意键返回主页面!");break;
		default:break;
		}	
		getch();
		system("cls");
	}while(n!=5);

}

vs2017环境下成功编译,vc6.0编译不通过 #include "stdafx.h" #include #include #include #include // 使用该计时器必须包含的文件 #pragma comment ( lib, "Winmm.lib" ) using namespace std; #define LONG 800 // 窗口长 #define WIDE 500 // 窗口宽 #define NUM 13 // 烟花种类数量宏定义 void Init_Fire(); // 初始化烟花 void Load_Image(); // 加载烟花图片 void Shoot(); // 发射烟花 void Chose(DWORD& t1); // 筛选烟花 void Show(DWORD* pMem); // 绽放烟花 void Erase(DWORD* pMem); // 随机擦除像素点 // 烟花结构 struct FIRE { int r; // 当前爆炸半径 int max_r; // 爆炸中心距离边缘最大半径 int x, y; // 爆炸中心在窗口的坐标 int cen_x, cen_y; // 爆炸中心相对图片左上角的坐标 int width, height; // 图片的宽高 int xy[240][240]; // 储存图片像素点 bool show; // 是否绽放 bool draw; // 开始输出像素点 DWORD t1, t2, dt; // 绽放速度 }Fire[NUM]; // 烟花弹结构 struct JET { int x, y; // 喷射点坐标 int hx, hy; // 最高点坐标------将赋值给 FIRE 里面的 x, y int height; // 烟花高度 bool shoot; // 是否可以发射 DWORD t1, t2, dt; // 发射速度 IMAGE img[2]; // 储存花弹一亮一暗图片 byte n : 1; // 图片下标 }Jet[NUM]; // 初始化烟花参数 void Init_Fire() { // 分别为:烟花中心到图片边缘的最远距离、烟花中心到图片左上角的距离 (x、y) 两个分量 int r[13] = { 120, 120, 155, 123, 130, 147, 138, 138, 130, 135, 140, 132, 155 }; int x[13] = { 120, 120, 110, 117, 110, 93, 102, 102, 110, 105, 100, 108, 110 }; int y[13] = { 120, 120, 85, 118, 120, 103, 105, 110, 110, 120, 120, 104, 85 }; for (int i = 0; i < NUM; i++) // 初始化烟花 { Fire[i].x = 0; // 烟花中心坐标 Fire[i].y = 0; Fire[i].width = 240; // 图片宽 Fire[i].height = 240; // 图片高 Fire[i].max_r = r[i]; // 最大半径 Fire[i].cen_x = x[i]; // 中心距左上角距离 Fire[i].cen_y = y[i]; Fire[i].show = false; // 是否绽放 Fire[i].dt = 5; // 绽放时间间隔 Fire[i].t1 = timeGetTime(); Fire[i].r = 0; // 从 0 开始绽放 Jet[i].x = -240; // 烟花弹左上角坐标 Jet[i].y = -240; Jet[i].hx = -240; // 烟花弹发射最高点坐标 Jet[i].hy = -240; Jet[i].height = 0; // 发射高度 Jet[i].t1 = timeGetTime(); Jet[i].dt = rand() % 10; // 发射速度时间间隔 Jet[i].n = 0; // 烟花弹闪烁图片下标 Jet[i].shoot = false; // 是否发射 } } // 加载图片 void Load_Image() { IMAGE fm, gm; loadimage(&fm, _T("fire/flower.jpg"), 3120, 240); for (int i = 0; i < NUM; i++) { SetWorkingImage(&fm); getimage(&gm, i * 240, 0, 240, 240); SetWorkingImage(&gm); for (int a = 0; a < 240; a++) for (int b = 0; b < 240; b++) Fire[i].xy[a][b] = getpixel(a, b); } IMAGE sm; loadimage(&sm, _T("fire/shoot.jpg"), 200, 50); for (int i = 0; i 100) { int n = rand() % 20; if (n < 13 && Jet[n].shoot == false && Fire[n].show == false) { Jet[n].x = rand() % LONG; Jet[n].y = rand() % 100 + LONG / 2; Jet[n].hx = Jet[n].x; Jet[n].hy = rand() % LONG / 3; Jet[n].height = Jet[n].y - Jet[n].hy; Jet[n].shoot = true; putimage(Jet[n].x, Jet[n].y, &Jet[n].img[Jet[n].n], SRCINVERT); } t1 = t2; } } // 扫描烟花弹并发射 void Shoot() { for (int i = 0; i Jet[i].dt&& Jet[i].shoot == true) { putimage(Jet[i].x, Jet[i].y, &Jet[i].img[Jet[i].n], SRCINVERT); // 烟花弹的上升 if (Jet[i].y > Jet[i].hy) { Jet[i].n++; Jet[i].y -= 5; } putimage(Jet[i].x, Jet[i].y, &Jet[i].img[Jet[i].n], SRCINVERT); if ((Jet[i].y - Jet[i].hy) * 4 < Jet[i].height) // 上升到高度的 3 / 4,减速 Jet[i].dt = rand() % 4 + 10; if (Jet[i].y <= Jet[i].hy) // 上升到最大高度 { putimage(Jet[i].x, Jet[i].y, &Jet[i].img[Jet[i].n], SRCINVERT); // 擦掉烟花弹 Fire[i].x = Jet[i].hx + 10; // 在烟花弹中间爆炸 Fire[i].y = Jet[i].hy; // 在最高点绽放 Fire[i].show = true; // 开始绽放 Jet[i].shoot = false; // 停止发射 } Jet[i].t1 = Jet[i].t2; } } } // 绽放烟花 void Show(DWORD* pMem) { // 烟花个阶段绽放时间间隔,制作变速绽放效果 int drt[16] = { 5, 5, 5, 5, 5, 6, 25, 25, 25, 25, 55, 55, 55, 55, 55 }; for (int i = 0; i Fire[i].dt&& Fire[i].show == true) { if (Fire[i].r = Fire[i].max_r - 1) { Fire[i].draw = false; Init_Fire(); } Fire[i].t1 = Fire[i].t2; } // 如果该号炮花可爆炸,根据当前爆炸半径画烟花,颜色值接近黑色的不输出。 if (Fire[i].draw) { for (double a = 0; a <= 6.28; a += 0.01) { int x1 = (int)(Fire[i].cen_x + Fire[i].r * cos(a)); // 相对于图片左上角的坐标 int y1 = (int)(Fire[i].cen_y -
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值