【情人节.爱心】

#include<stdio.h>
#include<Windows.h>
#include<conio.h>
#include"love.h"
//进度条效果
void load();
//设置背景色、前景色
void SetColor(unsigned short forewardColor,unsigned short background);
//打印一行******
void outputRepeat(const char* text);
//打印爱心选择文本
void outputText();

void printflove();


void load()//进度条效果
{
    SetColor(0, 14);//黑色字,米黄色背景
    int i;
    for (i = 0; i <= 50; i++)
    {
        printf(" ");
        printf("%d%%", i * 2);
        Sleep(101 - i);
        printf("\b\b\b");//"\b"将输出位置左移一位
    }

    SetColor(15, 0);//白色字,黑色背景
    printf("\n加载完成!");
    Sleep(2000);
    system("cls");
}

void SetColor(unsigned short forewardColor, unsigned short background)
{
 // 获取输出设备的句柄
    HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE);
    //一个字节来设置(低四位前景色,高四位背景色)
    SetConsoleTextAttribute(hCon, forewardColor | background << 4);
}

//打印一行星星
void outputRepeat(const char* text)
{
    int i;
    for (i = 0; i <= 56; i++)
    {
        if (i >=20)
        {
            printf(text);
            Sleep(10);
        }
        else
        {
            printf(" ");
        }
    }
}

void outputText()
{
    printf("\n\t\t\t1.你需要什么样的心型:\n");
    printf("\n\t\t\t2.由love组成的心型!\n");
    printf("\n\t\t\t3.由随机字符组成的心型:\n");
    printf("\n\t\t\t4.由随机数字组成的心型型:\n");
    printf("\n\t\t\t5.由随机颜色组成的心型:\n");
    printf("\n\t\t\t6.退出!:\n");
}


int   main()
{
     load();
    int choose;//用户的选择
    const char* text = "*";
    do
    {   
        
        //打印2行**
        outputRepeat(text);
        printf("\n");
        outputRepeat(text);
        //打印爱心选择文本
          outputText();  
        outputRepeat(text);
        printf("\n");
        outputRepeat(text);
        
       //用户选择
         scanf_s("%d", &choose);
        //退出
         if (choose == 5)
         {
             return 0;
         }

         //打印爱心
         SetColor(4, 0);
         printflove(choose);

         printf("请按任意键回到上一级\n");
         _getch();
         system("cls");

    } while (1);

    return 0;

}

头文件

#pragma once

#include<math.h>
#include<stdio.h>

extern void SetColor(unsigned short ForeColor, unsigned short BackColor);

void  printflove(int loveType)
{
    int s = 0;
    for (float x = 1.3; x >= -1.1; x -= 0.1)
    {
        for (float y = -2; y <= 1.4; y += 0.053)
        {
            if (pow(x * x + y * y - 1, 3) - x * x * x * y * y <= 0)
            {
                switch (loveType)
                {
                case 1://love
                    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);
                    break;
                case 2://随机字母
                    printf("%c", rand() % 10 + rand() % 10 + 97);
                    Sleep(2);
                    break;
                case 3://随机数字
                    printf("%d", rand() % 10);
                    Sleep(2);
                    break;
                case 4:
                    SetColor(0, rand() % 6 + 10);
                    printf(" ");
                    Sleep(2);
                    break;
                default :
                    break;
                }
            }
            else
            {
                if (loveType == 4) SetColor(0, 0);
                printf(" ");

            }
        }
        printf("\n");
    }

}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值