用turtle 画出奥特曼
时间: 2024-05-08 11:03:18 浏览: 123
以下是用turtle库画出奥特曼的代码:
```python
import turtle
# 创建画布及画笔
win = turtle.Screen()
win.title("Draw Ultraman with Turtle")
pen = turtle.Turtle()
# 设置画笔颜色、粗细、速度等属性
pen.color('red')
pen.pensize(5)
pen.speed(1)
# 画奥特曼的身体
pen.fillcolor('red')
pen.begin_fill()
pen.forward(100)
pen.left(90)
pen.circle(-50, 180)
pen.left(90)
pen.forward(100)
pen.right(90)
pen.circle(-50, 180)
pen.right(90)
pen.forward(100)
pen.end_fill()
# 画奥特曼的头部
pen.penup()
pen.goto(0, 150)
pen.pendown()
pen.circle(-50)
pen.penup()
pen.goto(-20, 180)
pen.pendown()
pen.circle(-10)
pen.penup()
pen.goto(20, 180)
pen.pendown()
pen.circle(-10)
# 画奥特曼的眼睛
pen.fillcolor('white')
pen.penup()
pen.goto(-30, 130)
pen.pendown()
pen.begin_fill()
pen.circle(-5)
pen.end_fill()
pen.penup()
pen.goto(30, 130)
pen.pendown()
pen.begin_fill()
pen.circle(-5)
pen.end_fill()
pen.fillcolor('black')
pen.penup()
pen.goto(-30, 130)
pen.pendown()
pen.begin_fill()
pen.circle(-2)
pen.end_fill()
pen.penup()
pen.goto(30, 130)
pen.pendown()
pen.begin_fill()
pen.circle(-2)
pen.end_fill()
# 画奥特曼的手臂
pen.penup()
pen.goto(-100, 50)
pen.pendown()
pen.fillcolor('red')
pen.begin_fill()
pen.right(45)
pen.forward(70)
pen.right(180)
pen.circle(-20, -180)
pen.right(180)
pen.forward(70)
pen.right(180)
pen.circle(-10, -180)
pen.right(180)
pen.forward(40)
pen.end_fill()
pen.penup()
pen.goto(100, 50)
pen.pendown()
pen.fillcolor('red')
pen.begin_fill()
pen.left(45)
pen.forward(70)
pen.circle(-20, 180)
pen.forward(70)
pen.circle(-10, 180)
pen.forward(40)
pen.end_fill()
# 画奥特曼的腿
pen.penup()
pen.goto(-30, -50)
pen.pendown()
pen.fillcolor('red')
pen.begin_fill()
pen.left(90)
pen.forward(50)
pen.left(180)
pen.circle(-20, -180)
pen.right(180)
pen.forward(90)
pen.right(180)
pen.circle(-10, -180)
pen.right(180)
pen.forward(70)
pen.end_fill()
pen.penup()
pen.goto(30, -50)
pen.pendown()
pen.fillcolor('red')
pen.begin_fill()
pen.left(180)
pen.forward(50)
pen.left(180)
pen.circle(-20, -180)
pen.right(180)
pen.forward(90)
pen.right(180)
pen.circle(-10, -180)
pen.right(180)
pen.forward(70)
pen.end_fill()
# 隐藏画笔
pen.hideturtle()
# 关闭画布
win.exitonclick()
```
运行代码后,窗口会弹出,画出的奥特曼如下图所示:
![奥特曼](https://cdn.luogu.com.cn/upload/image_hosting/md5/5de2f8e7bcf5c300a5cbe40b7b4c99ff.png)
阅读全文