当前位置: 首页 > news >正文

C语言实现的冰墩墩

在windows系统下,vs 2022编译。

其中#include <graphics.h>需要自己下载安装。

环境配置没什么难度,直接上demo。

代码如下:

#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 DrawHat();
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() {
    setfillcolor(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, 46, BLACK);
    setfillcolor(BLACK);
    floodfill(-109, -131, BLACK);
    floodfill(109, -131, BLACK);
    setfillcolor(WHITE);
    solidcircle(-92, -137, 30);
    solidcircle(92, -137, 30);
    setfillcolor(BLACK);
    solidcircle(-92, -137, 26);
    solidcircle(92, -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() {
    setfillcolor(BLACK);
    setlinestyle(PS_SOLID, 8);
    setfillcolor(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);
    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 += 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 += 0.01)
    {
        m = i;
        n=-size * (((sin(i)) * sqrt(fabs(cos(i)))) / (sin(i) + 1.14142))- 2*sin(i) + 2;
        x = m * cos(m) + x0;
        y = n * sin(n) + y0;
        setfillcolor(C);
        solidcircle((int)x, (int)y, 1);
    }
}

实现如下:

相关文章:

  • 搭建简易的rtsp服务器
  • Android Studio编译问题
  • HO与OH差异之Navigation
  • GitHub供应链攻击事件:Coinbase遭袭,218个仓库暴露,CI/CD密钥泄露
  • jangow靶机攻略
  • Vue.js 过滤器(Filters):简化文本格式化的利器
  • 第十四届蓝桥杯省赛电子类单片机学习记录(客观题)
  • 2025 JMeter平替的五款工具
  • 中间件框架漏洞攻略
  • 室分覆盖(室内分布系统)详解
  • 二叉搜索树的最近公共祖先 删除二叉搜索树中的节点 修剪二叉搜索树(Java)
  • ClickHouse怎么学习
  • 数据库—sql语法基础
  • 健身房管理系统(源码+数据库)
  • 《HarmonyOS Next自定义TabBar页签凸起和凹陷案例与代码》
  • chatshare.xyz和chatshare.biz的差别和渠道!
  • 【踩坑日记】IDEA的ctrl+r快捷键冲突无法使用
  • 前端如何用canvas来做电影院选票功能
  • K8S学习之基础四十七:k8s中部署fluentd
  • Java多线程与高并发专题——如何利用 CompletableFuture 解决“聚合打车服务平台”的问题?
  • 朝鲜新型驱逐舰“崔贤”号进行多项武器试验
  • 东风着陆场近日气象条件满足神舟十九号安全返回要求
  • 工行一季度净赚841亿元降3.99%,营收降3.22%
  • 初步结果显示加拿大自由党赢得大选,外交部回应
  • 国家发改委:我国能源进口来源多元,企业减少甚至停止自美能源进口对国内能源供应没有影响
  • 野猪穿过江苏电视台楼前广场,被抓捕后送往红山森林动物园