python绘制奥特曼
时间: 2023-10-12 16:17:26 浏览: 346
以下是利用Python中的turtle库绘制奥特曼的代码:
```python
import turtle
# 设置窗口大小和背景色
turtle.setup(800, 600)
turtle.bgcolor("black")
# 绘制奥特曼的身体
turtle.speed(10)
turtle.color("red")
turtle.fillcolor("red")
turtle.begin_fill()
for i in range(180):
turtle.forward(2)
turtle.left(1)
turtle.left(45)
for i in range(90):
turtle.forward(50)
turtle.right(1)
turtle.right(90)
for i in range(180):
turtle.forward(2)
turtle.left(1)
turtle.right(45)
for i in range(90):
turtle.forward(50)
turtle.right(1)
turtle.end_fill()
# 绘制奥特曼的眼睛
turtle.penup()
turtle.goto(-20, 100)
turtle.pendown()
turtle.color("white")
turtle.fillcolor("white")
turtle.begin_fill()
turtle.circle(20)
turtle.end_fill()
turtle.penup()
turtle.goto(20, 100)
turtle.pendown()
turtle.begin_fill()
turtle.circle(20)
turtle.end_fill()
# 绘制奥特曼的眼珠
turtle.penup()
turtle.goto(-15, 120)
turtle.pendown()
turtle.color("black")
turtle.fillcolor("black")
turtle.begin_fill()
turtle.circle(8)
turtle.end_fill()
turtle.penup()
turtle.goto(25, 120)
turtle.pendown()
turtle.begin_fill()
turtle.circle(8)
turtle.end_fill()
# 绘制奥特曼的嘴巴
turtle.penup()
turtle.goto(-40, 50)
turtle.pendown()
turtle.color("white")
turtle.pensize(5)
turtle.right(90)
turtle.circle(40, 180)
# 绘制奥特曼的手臂
turtle.penup()
turtle.goto(-140, -30)
turtle.pendown()
turtle.color("red")
turtle.fillcolor("red")
turtle.begin_fill()
turtle.right(90)
turtle.forward(70)
turtle.right(90)
turtle.forward(30)
turtle.right(90)
turtle.forward(70)
turtle.right(90)
turtle.forward(30)
turtle.end_fill()
turtle.penup()
turtle.goto(140, -30)
turtle.pendown()
turtle.color("red")
turtle.fillcolor("red")
turtle.begin_fill()
turtle.right(90)
turtle.forward(70)
turtle.right(90)
turtle.forward(30)
turtle.right(90)
turtle.forward(70)
turtle.right(90)
turtle.forward(30)
turtle.end_fill()
# 绘制奥特曼的腿
turtle.penup()
turtle.goto(-60, -170)
turtle.pendown()
turtle.color("red")
turtle.fillcolor("red")
turtle.begin_fill()
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(40)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(40)
turtle.end_fill()
turtle.penup()
turtle.goto(60, -170)
turtle.pendown()
turtle.color("red")
turtle.fillcolor("red")
turtle.begin_fill()
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(40)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(40)
turtle.end_fill()
turtle.hideturtle() # 隐藏画笔
turtle.done() # 完成绘图
```
运行代码后,将会在窗口中绘制出奥特曼的图案。
阅读全文