| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 908 人关注过本帖
标题:帮忙看看哪里出错了,代码不能运行。
只看楼主 加入收藏
xinyuexch
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2022-5-14
收藏
 问题点数:0 回复次数:2 
帮忙看看哪里出错了,代码不能运行。
#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);
    }
}
搜索更多相关主题的帖子: 绘制 sin BLACK void int 
2022-05-14 17:13
yahooboby
Rank: 2
等 级:论坛游民
威 望:2
帖 子:6
专家分:40
注 册:2016-4-27
收藏
得分:0 
没有出错,运行后是一个熊猫2022年的
2022-05-24 13:19
apull
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:三体星系
等 级:版主
威 望:216
帖 子:1479
专家分:9035
注 册:2010-3-16
收藏
得分:0 
显示一个冰墩墩。
使用vs2022 + easyX编译成功。
VC6会提示DrawLogo中的r = { -116, 175, 116, 250 };错误。
修改为
RECT r2 = { -116, 175, 116, 250 };
drawtext(_T("2022"), &r2, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
后vc6成功编译
图片附件: 游客没有浏览图片的权限,请 登录注册


2022-05-25 08:51
快速回复:帮忙看看哪里出错了,代码不能运行。
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016143 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved