今日是七夕节,虽然还是一个人,但找了找以前写的代码分享一下!!!
代码简单易懂:
1、利用Easyx2022
2、主要运用的有关函数:文字输出、绘图、循环+颜色变换
#include<bits/stdc++.h>
#include<graphics.h>
#include<conio.h>
#define PI 3.1415926353897
int size_heart = 100;
COLORREF color[] = { WHITE,YELLOW,BROWN,GREEN,BLUE,0x00FFFF,0xF0F8FF,0x38B0DE,0xD8D8BF,0x70DB93 };
int main()
{
srand((unsigned int)time(NULL));
initgraph(1000, 1000, NULL);
setorigin(500, 400);
settextcolor(RED);
settextstyle(30, 20, _T("黑体"));
RECT rect = { -100, 000, 100, 200 };
while (!_kbhit())
{
//刷新页面
cleardevice();
//字体
settextstyle(40, 30, _T("黑体"));
outtextxy(-100, -200, _T("爱心代码"));
settextstyle(30, 20, _T("黑体"));
drawtext(_T( "七夕节快乐"),&rect, DT_VCENTER | DT_CENTER | DT_SINGLELINE);
while (size_heart <=125)
{
BeginBatchDraw();
size_heart += 5;
//爱心函数的参数方程
for (double t = 0;t <= 2 * PI;t += 0.1)
{
double r = sin(t) * sqrt(abs(cos(t))) / (sin(t) + sqrt(2)) - 2 * sin(t) + 2;
int x = size_heart * r * sin(t + PI / 2);
int y = size_heart * r * cos(t + PI / 2);
outtextxy(x, y, _T("❤"));
}
EndBatchDraw();
Sleep(300);
}
//变化范围
if (size_heart > 125)
{
size_heart = 100;
//随机颜色
setbkcolor(color[rand()%10]);
Sleep(500);
}
}
system("pause");
closegraph();
return 0;
}
望指正!!!