用Python里面的turle 画个派大星
时间: 2024-01-21 15:19:41 浏览: 101
使用Python的turtle模块画图
好的,以下是用Python中的turtle库画派大星的代码:
```python
import turtle
# 设置画布大小和背景颜色
turtle.setup(800, 600)
turtle.bgcolor("#3F5B9B")
# 画派大星的头
turtle.penup()
turtle.goto(-100, 100)
turtle.pendown()
turtle.begin_fill()
turtle.color("#F7D117")
for i in range(5):
turtle.forward(200)
turtle.right(144)
turtle.end_fill()
# 画派大星的眼睛
turtle.penup()
turtle.goto(0, 150)
turtle.pendown()
turtle.begin_fill()
turtle.color("#FFFFFF")
turtle.circle(30)
turtle.end_fill()
turtle.penup()
turtle.goto(0, 180)
turtle.pendown()
turtle.begin_fill()
turtle.color("#000000")
turtle.circle(10)
turtle.end_fill()
# 画派大星的胡须
turtle.penup()
turtle.goto(-70, 50)
turtle.pendown()
turtle.pensize(10)
turtle.color("#000000")
turtle.right(25)
turtle.forward(60)
turtle.penup()
turtle.goto(-70, 30)
turtle.pendown()
turtle.right(-50)
turtle.forward(60)
turtle.penup()
turtle.goto(-70, 10)
turtle.pendown()
turtle.right(25)
turtle.forward(60)
turtle.penup()
turtle.goto(70, 50)
turtle.pendown()
turtle.right(125)
turtle.forward(60)
turtle.penup()
turtle.goto(70, 30)
turtle.pendown()
turtle.right(-50)
turtle.forward(60)
turtle.penup()
turtle.goto(70, 10)
turtle.pendown()
turtle.right(25)
turtle.forward(60)
# 画派大星的身体
turtle.penup()
turtle.goto(-150, -50)
turtle.pendown()
turtle.begin_fill()
turtle.color("#F7D117")
for i in range(5):
turtle.forward(300)
turtle.right(144)
turtle.end_fill()
# 画派大星的裤子
turtle.penup()
turtle.goto(-70, -150)
turtle.pendown()
turtle.begin_fill()
turtle.color("#4E8BAF")
turtle.forward(140)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(140)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.end_fill()
# 画派大星的鞋子
turtle.penup()
turtle.goto(-100, -250)
turtle.pendown()
turtle.begin_fill()
turtle.color("#000000")
turtle.forward(40)
turtle.right(90)
turtle.forward(20)
turtle.right(90)
turtle.forward(40)
turtle.right(90)
turtle.forward(20)
turtle.right(90)
turtle.end_fill()
turtle.penup()
turtle.goto(60, -250)
turtle.pendown()
turtle.begin_fill()
turtle.color("#000000")
turtle.forward(40)
turtle.right(90)
turtle.forward(20)
turtle.right(90)
turtle.forward(40)
turtle.right(90)
turtle.forward(20)
turtle.right(90)
turtle.end_fill()
turtle.hideturtle()
turtle.done()
```
运行代码后,就可以在窗口中看到画出来的派大星了。
阅读全文