C语言写的控制台程序,黑白界面,略显枯燥,这里介绍个easyx库
EasyX Graphics Library 是针对 Visual C++ 的绘图库
详情请看:EasyX库使用入门
下面我们借用easyx库
一起来画个爱心给你的女神吧!
#include <graphics.h>
#include <conio.h>
#include <math.h>
#include<Windows.h>
void heart(int x0, int y0, int size, COLORREF C)
{
double m, n, x, y; double i;
//设置圆点的颜色
setfillcolor(RGB(221, 0, 27));
for (i = 0; i <= 2 * size; i = i + 0.02)
{
//产生极坐标点
m = i;
n = -size * (((sin(i)*sqrt(fabs(cos(i)))) / (sin(i) + 1.4142)) - 2 * sin(i) + 2);
//转换为笛卡尔坐标
x = n * cos(m) + x0;
y = n * sin(m) + y0;
//画小圆点
fillcircle(x, y, 3);
//延时
Sleep(30);
}
}
void text(int x , int y , int speed) {
//设置字体颜色
settextcolor(RGB(221, 0, 27));
//设置字体样式
settextstyle(20, 0, L"幼圆");
setbkmode(TRANSPARENT);
outtextxy(x += 30, y, L"送");
//延时输出
Sleep(speed);
outtextxy(x += 30, y, L"你");
Sleep(speed);
outtextxy(x += 30, y, L"一");
Sleep(speed);
outtextxy(x += 30, y, L"个");
Sleep(speed);
outtextxy(x += 30, y, L"小");
Sleep(speed);
outtextxy(x += 30, y, L"心");
Sleep(speed);
outtextxy(x += 30, y, L"心");
Sleep(speed);
}
int main()
{
//设置窗口大小
initgraph(640, 480);
//设置背景颜色
setbkcolor(WHITE);
cleardevice();
//输出文本
text(170,30,200);
//画爱心
heart(300, 130, 80, RGB(221, 0, 27));
//关闭绘图窗口
closegraph();
return 0;
}