page contents

用python代码画一个奥特曼

本文讲述了用python代码画一个奥特曼!具有很好的参考价值,希望对大家有所帮助。一起跟随六星小编过来看看吧,具体如下:

attachments-2022-12-YbdmCsyS639a83b05f46c.jpg本文讲述了用python代码画一个奥特曼!具有很好的参考价值,希望对大家有所帮助。一起跟随六星小编过来看看吧,具体如下:

上班闲来无事 画个凹凸曼给女同事博博她开心。

首先奥特曼是由斜的椭圆,圆角矩形,圆形,以及曲线的组成的。此处绘制中,主要应用了曲线的的绘制,将奥特曼画的比较饱满。

本次绘制过过程中,自己编写了两个函数。一个是绘制有倾斜角的椭圆,用来表示奥特曼的眼睛,这样可以使得奥特曼更加有灵魂。另一个是心形。在平时绘制别的东西时,如果需要,可以直接借鉴。

attachments-2022-12-jp5jSYOV639a82dc4297a.jpg源码:

///

// 程序名称:绘制奥特曼

// 编译环境:Mictosoft Visual Studio 2013, EasyX_20200315(beta)

// 最后修改:2020-6-10

//

 

#include<conio.h>

#include<graphics.h>

#include<math.h>

#define PI acos(-1.0)

double th = PI / 180;

 

// 绘制斜的椭圆

void DrawEllipse(int x0, int y0, int a, int b, int k, int color);

// 绘制心形

void heart(int x0, int y0, int size, COLORREF C);

 

int main()

{

initgraph(640, 640);

setbkcolor(WHITE);

cleardevice();

// 设置线的宽度

setlinestyle(PS_SOLID, 5);

setlinecolor(BLACK);

setfillcolor(RGB(238, 238, 238));

// 左耳朵

fillrectangle(175, 266, 190, 325);

fillrectangle(159, 281, 175, 315);

// 右耳朵

fillrectangle(393, 268, 410, 324);

fillrectangle(410, 286, 423, 311);

fillellipse(187, 196, 397, 402);

setfillcolor(WHITE);

fillroundrect(288, 146, 302, 242, 10, 20);

// 绘制左右眼睛

DrawEllipse(243, 297, 38, 30, -30, BLACK);

DrawEllipse(350, 297, 38, 30, 30, BLACK);

setfillcolor(RGB(248, 245, 143));

floodfill(243, 297, BLACK);

floodfill(350, 297, BLACK);

line(296, 422, 249, 394);

line(296, 422, 336, 394);

setfillcolor(RGB(235, 110, 69));

floodfill(295, 410, BLACK);

setfillcolor(RGB(137, 211, 211));

fillcircle(294, 432, 10);

// 绘制身体

arc(222, 399, 286, 591, 145.0 / 180 * PI, PI + 145.0 / 180 * PI);

arc(305, 413, 364, 591, PI + 35.0 / 180 * PI, 55.0 / 180 * PI);

line(224, 485, 359, 485);

line(224, 511, 278, 549);

line(278, 549, 312, 549);

line(312, 549, 360, 515);

setfillcolor(RGB(235, 110, 69));

floodfill(294, 517, BLACK);

setfillcolor(RGB(238, 238, 238));

floodfill(252, 554, BLACK);

floodfill(334, 559, BLACK);

// 绘制左边胳膊

arc(189, 387, 353, 647, 109.0 / 180 * PI, PI);

arc(189, 480, 223, 537, 10.0 / 180.0 * PI + PI, 0);

line(196, 471, 222, 491);

setfillcolor(RGB(235, 110, 69));

floodfill(207, 501, BLACK);

// 绘制右胳膊

arc(230, 319, 424, 455, 110.0 / 180 * PI + PI, 5.0 / 180 * PI);

arc(392, 360, 424, 395, -5.0 / 180 * PI, PI + PI / 2);

arc(310, 286, 402, 394, 70.0 / 180 * PI + PI, 150.0 / 180 * PI + PI);

line(372, 390, 394, 431);

setfillcolor(RGB(235, 110, 69));

floodfill(399, 402, BLACK);

// 给身体颜色

setfillcolor(RGB(238, 238, 238));

floodfill(296, 458, BLACK);

// 连接气球

line(463, 187, 422, 365);

heart(464, 67, 30, BLACK);

setfillcolor(RGB(235, 110, 69));

floodfill(464, 70, BLACK);

setfillcolor(RGB(255, 232, 201));

solidcircle(508, 70, 6);

_getch();

return 0;

}

 

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, 2);

}

}

 

void DrawEllipse(int x0, int y0, int a, int b, int k, int 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);

}

}

更多相关技术内容咨询欢迎前往并持续关注六星社区了解详情。

想高效系统的学习Python编程语言,推荐大家关注一个微信公众号:Python编程学习圈。每天分享行业资讯、技术干货供大家阅读,关注即可免费领取整套Python入门到进阶的学习资料以及教程,感兴趣的小伙伴赶紧行动起来吧。

attachments-2022-05-rLS4AIF8628ee5f3b7e12.jpg

  • 发表于 2022-12-15 10:18
  • 阅读 ( 786 )
  • 分类:Python开发

你可能感兴趣的文章

相关问题

0 条评论

请先 登录 后评论
王昭君
王昭君

209 篇文章

作家榜 »

  1. 轩辕小不懂 2403 文章
  2. 小柒 1320 文章
  3. Pack 1135 文章
  4. Nen 576 文章
  5. 王昭君 209 文章
  6. 文双 71 文章
  7. 小威 64 文章
  8. Cara 36 文章