使用Python的turtle库画出一个奥特曼打怪兽
时间: 2023-07-20 18:08:48 浏览: 164
python用turtle画画
好的,下面是使用Python的turtle库画出一个奥特曼打怪兽的代码:
```python
import turtle
# 设置画布和画笔
canvas = turtle.Screen()
canvas.bgcolor("black")
canvas.title("奥特曼打怪兽")
pen = turtle.Turtle()
pen.speed(0)
pen.penup()
pen.goto(-200, -100)
pen.pendown()
# 画怪兽
pen.color("green")
pen.begin_fill()
pen.left(45)
pen.forward(100)
pen.right(90)
pen.circle(50, 180)
pen.right(90)
pen.forward(100)
pen.end_fill()
# 画奥特曼
pen.penup()
pen.goto(50, -100)
pen.pendown()
pen.color("red")
pen.begin_fill()
pen.left(45)
pen.forward(100)
pen.right(90)
pen.circle(-50, 180)
pen.right(90)
pen.forward(100)
pen.end_fill()
# 画奥特曼的头部和手臂
pen.penup()
pen.goto(50, 0)
pen.pendown()
pen.color("red")
pen.begin_fill()
pen.circle(-50)
pen.end_fill()
pen.penup()
pen.goto(-50, 0)
pen.pendown()
pen.color("white")
pen.begin_fill()
pen.circle(-20)
pen.end_fill()
# 画奥特曼的腿和眼睛
pen.penup()
pen.goto(50, -100)
pen.pendown()
pen.color("white")
pen.begin_fill()
pen.circle(-20)
pen.end_fill()
pen.penup()
pen.goto(50, -220)
pen.pendown()
pen.color("red")
pen.begin_fill()
pen.circle(-30)
pen.end_fill()
# 完成画图,隐藏画笔
pen.hideturtle()
turtle.done()
```
运行以上代码后,会弹出一个窗口,显示奥特曼打怪兽的图像。
阅读全文