1.
SetConsoleTextAttribute(hCon, (ForeColor % 16) | (BackGroundColor % 16 * 16));
设置背景色与字体色,
https://blog.csdn.net/odaynot/article/details/7722240
遵循混色原理,用|隔开,FOREGROUND_INTENSITY用于变亮
2.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);
//SetColor(0,)
printf(” “);
Sleep(2);
}
else
{
SetColor(0, 0);
printf(” “);
}
}
printf(“\n”);
}
这是画♥,在区域内画“
3
.
_getch()
;接受但是不会printf
// OJ题目.cpp: 定义控制台应用程序的入口点。
//
#include “stdafx.h”
#include<stdio.h>
#include<math.h>
#include<windows.h>
#include<time.h>
#include<stdlib.h>
#include<conio.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”); //背景色0黑色,前景色E淡黄色
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_s(“%d”, &n,4);
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);
//SetColor(0,)
printf(” “);
Sleep(2);
}
else
{
SetColor(0, 0);
printf(” “);
}
}
printf(“\n”);
}
SetColor(15, 0);
printf(“绘制完成,按任意键返回主页面!”); break;
default:break;
}
_getch();
system(“cls”);
} while (n != 5);
}