帮忙看看哪里出错了,代码不能运行。
#include<graphics.h>#include<conio.h>
#include<math.h>
#define PI acos(-1.0)
#define WIDTH 800
#define HEIGHT 800
double th = PI / 180;
void DrawBack(); // 绘制背景
void DrawEar(); // 绘制耳朵
void DrawLeg(); // 绘制腿
void DrawArm(); // 绘制胳膊
void DrawBody(); // 绘制身体
void DrawEye(); // 绘制眼睛
void DrawNose(); // 绘制鼻子
void DrawMouth(); // 绘制嘴
void DrawColour(); // 绘制彩带
void DrawLogo(); // 绘制标志
void heart(int x0, int y0, int size, COLORREF C); // 绘制心
void DrawEllipse(int x0, int y0, int a, int b, int k, COLORREF color); // 绘制倾斜椭圆
int main()
{
initgraph(WIDTH, HEIGHT);
DrawBack();
setorigin(WIDTH / 2, HEIGHT / 2); // 设置坐标系
DrawEar(); // 绘制耳朵
DrawLeg(); // 绘制腿
DrawArm(); // 绘制胳膊
DrawBody(); // 绘制身体
DrawEye(); // 绘制眼睛
DrawNose(); // 绘制鼻子
DrawMouth(); // 绘制嘴
DrawColour(); // 绘制彩带
DrawLogo(); // 绘制标志
heart(330, -120, 10, RED);
setfillcolor(RED);
floodfill(330, -100, RED);
_getch();
return 0;
}
void DrawBack()
{
float H = 190; // 色相
float S = 1; // 饱和度
float L = 0.7f; // 亮度
for (int y = 0; y < HEIGHT; y++)
{
L += 0.0002f;
setlinecolor(HSLtoRGB(H, S, L));
line(0, y, WIDTH - 1, y);
}
}
void DrawEar()
{
setfillcolor(BLACK);
solidcircle(172, -300, 62);
solidcircle(-172, -300, 62);
}
void DrawLeg()
{
setfillcolor(BLACK);
solidellipse(44, 155, 168, 348);
solidellipse(-44, 155, -168, 348);
}
void DrawArm()
{
DrawEllipse(-267, 50, 100, 60, 50, BLACK);
DrawEllipse(297, -60, 100, 60, 50, BLACK);
setfillcolor(BLACK);
floodfill(-267, 50, BLACK);
floodfill(297, -60, BLACK);
}
void DrawBody()
{
setlinecolor(BLACK);
setlinestyle(PS_SOLID, 8);
setfillcolor(WHITE);
fillellipse(-270, -354, 270, 260);
}
void DrawEye()
{
DrawEllipse(109, -131, 84, 60, 314, BLACK);
DrawEllipse(-109, -131, 84, 60, -314, BLACK);
setfillcolor(BLACK);
floodfill(109, -131, BLACK);
floodfill(-109, -131, BLACK);
setfillcolor(WHITE);
setlinestyle(PS_SOLID, 1);
solidcircle(92, -137, 30);
solidcircle(-92, -137, 30);
setfillcolor(BLACK);
solidcircle(90, -137, 26);
solidcircle(-90, -137, 26);
setfillcolor(WHITE);
solidcircle(81, -146, 9);
solidcircle(-81, -146, 9);
}
void DrawNose()
{
setlinestyle(PS_SOLID, 1);
setfillcolor(BLACK);
solidellipse(-26, -106, 26, -63);
}
void DrawMouth()
{
setlinecolor(BLACK);
setlinestyle(PS_SOLID, 8);
arc(-43, -75, 43, -7, PI, 0);
}
void DrawColour()
{
setlinecolor(BLACK);
setlinestyle(PS_SOLID, 8);
setlinecolor(RGB(91, 198, 250));
ellipse(-205, -265, 205, 74);
setlinecolor(RGB(119, 216, 113));
ellipse(-215, -275, 215, 84);
setlinecolor(RGB(254, 122, 185));
ellipse(-225, -285, 225, 94);
}
void DrawLogo()
{
RECT r = { -116, 100, 116, 175 };
settextcolor(BLACK);
setbkmode(TRANSPARENT);
settextstyle(60, 0, _T("黑体"));
drawtext(_T("BeiJing"), &r, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
r = { -116, 175, 116, 250 };
drawtext(_T("2022"), &r, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
}
void DrawEllipse(int x0, int y0, int a, int b, int k, COLORREF color)
{
double i;
double x, y, tx, ty;
for (i = -180; i <= 180; i = i + 0.5)
{
x = a * cos(i * th);
y = b * sin(i * th);
tx = x;
ty = y;
x = tx * cos(k * th) - ty * sin(k * th) + x0;
y = y0 - (ty * cos(k * th) + tx * sin(k * th));
setfillcolor(color);
solidcircle((int)x, (int)y, 2);
}
}
void heart(int x0, int y0, int size, COLORREF C)
{
double m, n, x, y;
double i;
for (i = 0; i <= 2 * size; i = i + 0.01)
{
// 产生极坐标点
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;
setfillcolor(C);
solidcircle((int)x, (int)y, 1);
}
}