C语言项目(绘制多种爱心)

目录

项目介绍

         此项目是基于一个爱心模块进行多样处理,展现不一样视觉效果,希望大家能够喜欢!

项目内容

函数介绍

void jindutiao();                       //进度条 
void love_aixin();                    //绘制love 爱心 
void rand_math_aixin();         //绘制随机数爱心 
void rand_zifu_aixin();           //绘制随机字母爱心 
void zifu_aixin();                    //绘制 *字符爱心 
void rand_color_aixin();        //制随机颜色爱心 

项目源代码

完整代码如下:

#include<stdio.h>
#include<math.h>
#include<windows.h>
#include<time.h>
#include<stdlib.h>
#include<conio.h>
//自定义按钮名称
extern HHOOK   hHook;
extern LRESULT  __stdcall  CBTHookProc(long  nCode, WPARAM  wParam, LPARAM   lParam);

HHOOK   hHook;
LRESULT  __stdcall  CBTHookProc(long  nCode, WPARAM  wParam, LPARAM   lParam)
{
	if (nCode == HCBT_ACTIVATE)
	{
		SetDlgItemText((HWND)wParam, IDYES, TEXT("好看"));//YSE改为好看 
		SetDlgItemText((HWND)wParam, IDNO, TEXT("不好看"));//NO改为不好看 
		SetDlgItemText((HWND)wParam, IDOK, TEXT("嗯嗯"));//OK改为嗯嗯 
		SetDlgItemText((HWND)wParam, IDCANCEL,TEXT("好的,谢谢"));//取消改为好的,谢谢
		UnhookWindowsHookEx(hHook);
	}
	return  0;
}

//字体颜色和背景颜色设置 
void SetColor(unsigned short ForeColor, unsigned short BackGroundColor)
{
	HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleTextAttribute(hCon, (ForeColor % 16) | (BackGroundColor % 16 * 16));
}

void jindutiao();		//进度条 
void love_aixin();		//绘制love 爱心 
void rand_math_aixin(); //绘制随机数爱心 
void rand_zifu_aixin(); //绘制随机字符爱心 
void zifu_aixin();		//绘制 *字符爱心 
void rand_color_aixin();//制随机颜色爱心 

int i,n,a;
double x,y;

int main()
{
	//设置标题
	SetConsoleTitle("绘制多种爱心"); 
	//设置窗口大小
	system("mode con cols=107 lines=32") ;//分别对应长,高 
	
	jindutiao();		//进度条 
	
	do
	{	
        //菜单
		printf("\n\n");
		system("color 0F");//整个窗口字体颜色为白色 
        //两行 _
		for (i = 0; i <= 66; i++)
		{
			if (i >= 30)
			{
				printf("_");
				Sleep(10);
			}
			else
				printf(" ");
		}
		printf("\n");
		for (i = 0; i <= 66; i++)
		{
			if (i >= 30)
			{
				printf("_");
				Sleep(2);
			}
			else
				printf(" ");
		} 
		printf("\n");   
		printf("\n\t\t\t\t您想要一个怎样的心形呢?\n");
		printf("\n\t\t\t\t动动手指选择一个心仪爱心吧\n");
		printf("\n\t\t\t\t 1:由love组成的心形!\n");
		printf("\n\t\t\t\t 2:由随机字符组成的心形!\n");
		printf("\n\t\t\t\t 3:由随机数字组成的心形!\n");
		printf("\n\t\t\t\t 4:由 * 组成的心形!\n");
		printf("\n\t\t\t\t 5:由随机颜色组成的心形!\n");
		printf("\n\t\t\t\t 6:体验反馈!\n");
		printf("\n\t\t\t\t 0:退出!\n");
		for (i = 0; i <= 66; i++)
		{
			if (i >= 30)
			{
				printf("_");
				Sleep(2);
			}
			else
				printf(" ");
		}
		printf("\n");
		for (i = 0; i <= 66; i++)
		{
			if (i >= 30)
			{
				printf("_");
				Sleep(5);
			}
			else
				printf(" ");
		}    
		printf("\n\n\t\t\t\t");
		printf("输入您想要选择的序号:"); 
		scanf("%d", &n);
		if(n>0 && n<6)
		{
			printf("\n\t\t\t\t");
			printf("好的,请稍等,马上为您绘制"); 
			//加载点... 
			Sleep(800);
			printf(" .");
			Sleep(800);
			printf(" .");
			Sleep(800);
			printf(" .");
			Sleep(1000);
			system("cls");
		}else if(n==6){
			printf("\n\t\t\t\t");
			printf("好的,请稍等,正在进入反馈页面"); 
			//加载点... 
			Sleep(800);
			printf(" .");
			Sleep(800);
			printf(" .");
			Sleep(800);
			printf(" .");
			Sleep(1000);
			system("cls");
		}
        

		//绘制爱心界面 
		switch (n)
		{
			
			case 0: printf("\n\t\t\t\t");
					printf("感谢您的选择,咱们下次见,爱你哟~,Bey~!");
					break;
			case 1:	
					love_aixin(); 
					break;
			case 2:		
					rand_zifu_aixin();
					break;
			case 3:		
					rand_math_aixin(); 
					break;
			case 4:		
					zifu_aixin();
					break;
			case 5:
					rand_color_aixin();
					break;
			case 6: printf("请提出您的宝贵意见:\n\n"); 
					printf("    ");
					scanf("%d",&a);
					printf("\n\n好的,非常感谢您的反馈,祝您生活愉快,再见!"); 
					break;
			default:
					printf("\n\t\t\t\t");
					printf("非常抱歉,未找到您的需求!请稍后重试!感谢您的理解!");
					break;
		}
		_getch(); //获取任意键 
		if(n != 0 && n != 6){
			system("cls");
		} else{
			printf("\n");
		}
	}  while  (n  !=  0 && n != 6);
	
	hHook = SetWindowsHookEx(WH_CBT, (HOOKPROC)CBTHookProc, NULL, GetCurrentThreadId());
	if(MessageBox(NULL,("请问您认为爱心画的好不好看?"),("调查问卷"),MB_YESNO | MB_ICONQUESTION) == IDYES)
										//MB_ICONQUESTION 图标为提问图标			//判断是否点击的是                                      
	{	hHook = SetWindowsHookEx(WH_CBT, (HOOKPROC)CBTHookProc, NULL, GetCurrentThreadId());
		MessageBox(NULL,("谢谢夸奖,我会再接再厉的,爱你哟!"),("调查问卷"),MB_OK | MB_ICONINFORMATION );
		hHook = SetWindowsHookEx(WH_CBT, (HOOKPROC)CBTHookProc, NULL, GetCurrentThreadId());
		MessageBox(NULL,("最后祝您生活愉快,咱们下次见!"),("调查问卷"),MB_OKCANCEL | MB_ICONINFORMATION);
	}
	else
	{	
		hHook = SetWindowsHookEx(WH_CBT, (HOOKPROC)CBTHookProc, NULL, GetCurrentThreadId());
		MessageBox(NULL,("不,想必是您没看完呢"),("调查问卷"),MB_OK | MB_ICONINFORMATION);
		
		hHook = SetWindowsHookEx(WH_CBT, (HOOKPROC)CBTHookProc, NULL, GetCurrentThreadId());
		MessageBox(NULL,("虽然没有后得到您中肯的夸奖,但是我是会再接再厉的!"),("调查问卷"),MB_OK | MB_ICONINFORMATION);
		
		hHook = SetWindowsHookEx(WH_CBT, (HOOKPROC)CBTHookProc, NULL, GetCurrentThreadId());
		MessageBox(NULL,("最后祝您生活愉快,咱们下次见!"),("调查问卷"),MB_OKCANCEL | MB_ICONINFORMATION);
	}
}

void jindutiao()
{
	int i; 
	for (i = 1; i <= 50; i++)//进度条 
	{
		SetColor(0, 15);//字体背景颜色 
		printf("  ");
		printf("已加载 %d% %", 2 * i);
		Sleep(110 - 2 * i);
		printf("\b\b\b\b\b\b\b\b\b\b");
	}
	
	SetColor(15, 0);//字体颜色 
	printf("\b\n\n\t\t\t\t加载完成!即将进入");
	
	//加载点... 
	{	Sleep(800);
		printf(" .");
		Sleep(800);
		printf(" .");
		Sleep(800);
		printf(" .");
		Sleep(1000);
		system("cls");
	}	
}

void love_aixin()
{
	system("color 0c");
	printf("\n\n");
	int s=0;
	 
	for (x = 1.3; x >= -1.5; x -= 0.1193)
	{
		for (y = -2.6; 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(1);
					}
					else
						printf(" ");
			}
			printf("\n");
	}
	SetColor(15, 0);
	printf("\n");
	printf("您要的爱心已绘制完毕,如果您还想要尝试其它的爱心,请按任意键返回主页面哦!");
}
void rand_zifu_aixin()
{
	system("color 0c");
	printf("\n\n");
	for (x = 1.3; x >= -1.1; x -= 0.1193)
	{
		for (y = -2.6; 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(1);
				}
				else
					printf(" ");
			}
			printf("\n");
	}
	SetColor(15, 0);
	printf("\n");
	printf("您要的爱心已绘制完毕,如果您还想要尝试其它的爱心,请按任意键返回主页面哦!");
}
void rand_math_aixin()
{
	system("color 0c");                                                                  
	printf("\n\n");                                                                      
	                                                                                      
	for (x = 1.3; x >= -1.1; x -= 0.1193)                                                
	{                                                                                    
		for (y = -2.6; 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(1);                                                                
			}                                                                            
			else                                                                         
				printf(" ");                                                             
		}    printf("\n");                                                               
	}                                                                                    
	SetColor(15, 0);                                                                     
	printf("\n");                                                                        
	printf("您要的爱心已绘制完毕,如果您还想要尝试其它的爱心,请按任意键返回主页面哦!");
	
}
void zifu_aixin()
{
	system("color 0c");                                                                  
	printf("\n\n");                                                                      
	                                                                                   
	for (x = 1.3; x >= -1.1; x -= 0.12)                                                  
	{                                                                                    
		for (y = -2.6; y <= 1.4; y += 0.053)                                             
		{                                                                                
			if (pow(x*x + y*y - 1, 3) - x*x*x*y*y <= 0)                                  
			{                                                                            
				printf("*");                                                             
				Sleep(1);                                                                
			}                                                                            
			else                                                                         
				printf(" ");                                                             
		}    printf("\n");                                                               
	}                                                                                    
	SetColor(15, 0);                                                                     
	printf("\n");                                                                        
	printf("您要的爱心已绘制完毕,如果您还想要尝试其它的爱心,请按任意键返回主页面哦!");
	
}
void rand_color_aixin()
{
	printf("\n\n");                                                                      
		                                                                                     
	for (x = 1.3; x >= -1.1; x -= 0.1193)                                                
	{                                                                                    
		for (y = -2.6; 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(1);                                                                
			}                                                                            
			else                                                                         
			{                                                                            
	 			SetColor(0, 0);                                                          
	 			printf(" ");                                                             
	 		}                                                                            
	 	}                                                                                
	 	printf("\n");                                                                    
 	}                                                                                    
	 SetColor(15, 0);                                                                     
	 printf("\n");                                                                        
	 printf("您要的爱心已绘制完毕,如果您还想要尝试其它的爱心,请按任意键返回主页面哦!");
 }	

项目效果 

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

萌新发文啦~

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值