使用Python的turtle库画出一个奥特曼打怪兽
时间: 2023-03-20 07:03:45 浏览: 1485
好的,以下是使用Python的turtle库画出一个奥特曼打怪兽的代码示例:
```python
import turtle
# 创建画布和画笔
canvas = turtle.Screen()
pen = turtle.Turtle()
# 画奥特曼
def draw_ultraman():
pen.penup()
pen.goto(-100, 0)
pen.pendown()
pen.color('red', 'red')
pen.begin_fill()
pen.left(45)
pen.forward(100)
pen.circle(50, 180)
pen.forward(100)
pen.left(90)
pen.circle(50, 180)
pen.forward(100)
pen.end_fill()
# 画怪兽
def draw_monster():
pen.penup()
pen.goto(100, 0)
pen.pendown()
pen.color('green', 'green')
pen.begin_fill()
pen.right(45)
pen.forward(100)
for i in range(4):
pen.circle(-50, 90)
pen.end_fill()
# 奥特曼打怪兽
def ultraman_vs_monster():
pen.penup()
pen.goto(-50, 50)
pen.pendown()
pen.color('blue')
pen.write('奥特曼\nVS\n怪兽', font=('Arial', 20, 'normal'))
pen.penup()
pen.goto(-80, -50)
pen.pendown()
pen.color('white')
pen.write('攻击!', font=('Arial', 20, 'normal'))
pen.penup()
pen.goto(-100, -100)
pen.pendown()
pen.color('yellow')
pen.begin_fill()
pen.circle(20)
pen.end_fill()
# 调用函数画图
draw_ultraman()
draw_monster()
ultraman_vs_monster()
# 隐藏画笔并保持画面不关闭
pen.hideturtle()
turtle.done()
```
运行该程序,即可在屏幕上看到一个奥特曼打怪兽的画面。
阅读全文