在Windows系统下用python编写一个的程序画出钢铁侠
时间: 2023-06-19 11:02:51 浏览: 96
实现这个任务,我们需要使用Python的一个图形库——turtle。下面是实现绘制钢铁侠的代码:
```python
import turtle
# 设置画笔属性
turtle.pensize(5)
turtle.pencolor('#D63433')
turtle.fillcolor('#D63433')
# 绘制头部
turtle.begin_fill()
turtle.circle(100)
turtle.end_fill()
# 绘制眼睛
turtle.penup()
turtle.goto(-50, 160)
turtle.pendown()
turtle.fillcolor('#FFFFFF')
turtle.begin_fill()
turtle.circle(20)
turtle.end_fill()
turtle.penup()
turtle.goto(50, 160)
turtle.pendown()
turtle.begin_fill()
turtle.circle(20)
turtle.end_fill()
# 绘制眼球
turtle.pencolor('#000000')
turtle.fillcolor('#000000')
turtle.penup()
turtle.goto(-40, 170)
turtle.pendown()
turtle.begin_fill()
turtle.circle(5)
turtle.end_fill()
turtle.penup()
turtle.goto(40, 170)
turtle.pendown()
turtle.begin_fill()
turtle.circle(5)
turtle.end_fill()
# 绘制嘴巴
turtle.pencolor('#000000')
turtle.penup()
turtle.goto(-50, 100)
turtle.pendown()
turtle.circle(50, 180)
# 绘制身体
turtle.penup()
turtle.goto(0, 0)
turtle.pendown()
turtle.fillcolor('#2D3436')
turtle.begin_fill()
turtle.forward(200)
turtle.right(90)
turtle.forward(150)
turtle.right(90)
turtle.forward(200)
turtle.right(90)
turtle.forward(150)
turtle.end_fill()
# 绘制胸部反光部分
turtle.penup()
turtle.goto(0, 75)
turtle.pendown()
turtle.fillcolor('#FFFFFF')
turtle.begin_fill()
turtle.circle(50)
turtle.end_fill()
# 绘制手臂
turtle.penup()
turtle.goto(-100, 0)
turtle.pendown()
turtle.fillcolor('#D63433')
turtle.begin_fill()
turtle.right(30)
turtle.forward(100)
turtle.left(60)
turtle.forward(50)
turtle.left(60)
turtle.forward(100)
turtle.end_fill()
turtle.penup()
turtle.goto(100, 0)
turtle.pendown()
turtle.fillcolor('#D63433')
turtle.begin_fill()
turtle.left(30)
turtle.forward(100)
turtle.right(60)
turtle.forward(50)
turtle.right(60)
turtle.forward(100)
turtle.end_fill()
# 绘制手掌
turtle.penup()
turtle.goto(-75, -50)
turtle.pendown()
turtle.fillcolor('#FFFFFF')
turtle.begin_fill()
turtle.circle(30)
turtle.end_fill()
turtle.penup()
turtle.goto(75, -50)
turtle.pendown()
turtle.fillcolor('#FFFFFF')
turtle.begin_fill()
turtle.circle(30)
turtle.end_fill()
# 绘制腿
turtle.penup()
turtle.goto(-50, -150)
turtle.pendown()
turtle.fillcolor('#D63433')
turtle.begin_fill()
turtle.right(30)
turtle.forward(100)
turtle.left(60)
turtle.forward(50)
turtle.left(60)
turtle.forward(100)
turtle.end_fill()
turtle.penup()
turtle.goto(50, -150)
turtle.pendown()
turtle.fillcolor('#D63433')
turtle.begin_fill()
turtle.left(30)
turtle.forward(100)
turtle.right(60)
turtle.forward(50)
turtle.right(60)
turtle.forward(100)
turtle.end_fill()
turtle.penup()
turtle.goto(-75, -200)
turtle.pendown()
turtle.fillcolor('#000000')
turtle.begin_fill()
turtle.circle(30)
turtle.end_fill()
turtle.penup()
turtle.goto(75, -200)
turtle.pendown()
turtle.fillcolor('#000000')
turtle.begin_fill()
turtle.circle(30)
turtle.end_fill()
turtle.done()
```
代码中,我们首先设置画笔属性,然后依次绘制头部、眼睛、眼球、嘴巴、身体、胸部反光部分、手臂、手掌、腿和脚。最后调用turtle.done()方法显示绘制结果。运行代码后,你将看到一个钢铁侠形象的绘制结果。
相关推荐
![application/msword](https://img-home.csdnimg.cn/images/20210720083327.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)