完成童年的梦想,用python画一个奥特曼

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

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

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

源码

///
// 程序名称:绘制奥特曼
// 编译环境: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);
	}
}

  • 5
    点赞
  • 54
    收藏
    觉得还不错? 一键收藏
  • 8
    评论
### 回答1: 使用Python语言一个奥特曼可以使用Matplotlib库来实现,可以用一些简单的代码奥特曼的图像:import matplotlib.pyplot as plt fig = plt.figure() ax = fig.add_subplot(111, aspect='equal') ax.add_patch(plt.Rectangle((4,3), 1, 2, color='red')) ax.add_patch(plt.Rectangle((4.5,2), 1, 2, color='green')) ax.add_patch(plt.Rectangle((3.5,1), 1, 2, color='blue')) plt.show() ### 回答2: 要用Python语言一个奥特曼,可以使用turtle模块来实现绘图功能。下面是一个使用turtle模块绘制奥特曼的示例代码: ```python import turtle # 设置布和笔 canvas = turtle.Screen() pen = turtle.Turtle() # 设置奥特曼的颜色和尺寸 pen.color("red") pen.pensize(3) # 绘制奥特曼的头部 pen.circle(50) # 绘制奥特曼的身体 pen.right(90) pen.forward(100) pen.right(90) pen.forward(50) pen.right(90) pen.forward(100) # 绘制奥特曼的左手臂 pen.right(180) pen.forward(50) pen.left(90) pen.forward(50) pen.left(90) pen.forward(50) pen.right(180) pen.forward(50) # 绘制奥特曼的右手臂 pen.right(90) pen.forward(50) pen.left(90) pen.forward(50) pen.left(90) pen.forward(50) pen.right(180) pen.forward(50) # 绘制奥特曼的左腿 pen.right(90) pen.forward(100) pen.left(45) pen.forward(70) pen.right(180) pen.forward(70) pen.left(90) pen.forward(70) # 绘制奥特曼的右腿 pen.left(90) pen.forward(70) pen.right(180) pen.forward(70) pen.left(45) pen.forward(100) # 绘制奥特曼的眼睛 eye_size = 10 pen.penup() pen.goto(-20, 20) pen.pendown() pen.begin_fill() pen.circle(eye_size) pen.end_fill() pen.penup() pen.goto(20, 20) pen.pendown() pen.begin_fill() pen.circle(eye_size) pen.end_fill() # 绘制奥特曼的嘴巴 pen.penup() pen.goto(-30, 0) pen.pendown() pen.setheading(-60) pen.circle(30, 120) # 隐藏笔 pen.hideturtle() # 关闭布 canvas.exitonclick() ``` 运行以上代码,就可以在布上绘制出一个简单的奥特曼图形。你还可以根据需要对绘制的奥特曼进行颜色、尺寸和细节的调整。希望以上回答对你有所帮助! ### 回答3: 要使用Python语言来奥特曼,我们可以使用turtle库来实现。首先,我们需要导入turtle库: ``` import turtle ``` 然后,我们可以设置窗口的大小和颜色: ``` window = turtle.Screen() window.bgcolor("white") window.setup(width=800, height=600) ``` 接下来,我们需要创建一个笔来绘制奥特曼的身体: ``` body = turtle.Turtle() body.shape("square") body.color("red") body.penup() body.goto(0, -200) body.pendown() ``` 然后,我们可以使用turtle库提供的方法来奥特曼的身体轮廓: ``` body.begin_fill() body.circle(100) body.end_fill() body.hideturtle() ``` 接着,我们需要奥特曼的眼睛: ``` eyes = turtle.Turtle() eyes.shape("circle") eyes.color("white") eyes.penup() eyes.goto(-40, -50) eyes.pendown() eyes.begin_fill() eyes.circle(20) eyes.end_fill() eyes.penup() eyes.goto(40, -50) eyes.pendown() eyes.begin_fill() eyes.circle(20) eyes.end_fill() eyes.hideturtle() ``` 然后,我们可以奥特曼的嘴巴: ``` mouth = turtle.Turtle() mouth.shape("triangle") mouth.color("black") mouth.penup() mouth.goto(0, -100) mouth.pendown() mouth.begin_fill() mouth.goto(-30, -130) mouth.goto(30, -130) mouth.goto(0, -100) mouth.end_fill() mouth.hideturtle() ``` 最后,我们可以使用turtle库提供的方法来奥特曼的角色标志: ``` logo = turtle.Turtle() logo.penup() logo.goto(-80, 150) logo.pendown() logo.write("Ultraman", move=False, align="left", font=("Arial", 20, "bold")) logo.hideturtle() ``` 最后,我们可以使用turtle库提供的方法来保持窗口的显示: ``` turtle.done() ``` 以上就是用Python语言奥特曼的简单示例,当然你可以根据实际需求进行更加详细的绘制和美化。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值