python turtle 雪人
时间: 2023-12-27 07:25:40 浏览: 108
以下是使用Python的turtle库绘制雪人的示例代码:
```python
import turtle
# 创建画布
window = turtle.Screen()
window.bgcolor("sky blue")
# 创建画笔
pen = turtle.Turtle()
pen.speed(1)
# 绘制雪人的身体
pen.penup()
pen.goto(0, -100)
pen.pendown()
pen.begin_fill()
pen.circle(50)
pen.end_fill()
# 绘制雪人的头部
pen.penup()
pen.goto(0, 50)
pen.pendown()
pen.begin_fill()
pen.circle(30)
pen.end_fill()
# 绘制雪人的眼睛
pen.penup()
pen.goto(-10, 70)
pen.pendown()
pen.dot(5)
pen.penup()
pen.goto(10, 70)
pen.pendown()
pen.dot(5)
# 绘制雪人的鼻子
pen.penup()
pen.goto(0, 50)
pen.pendown()
pen.setheading(240)
pen.circle(30, 60)
pen.penup()
pen.goto(0, 50)
pen.pendown()
pen.setheading(300)
pen.circle(-30, 60)
# 绘制雪人的帽子
pen.penup()
pen.goto(-40, 110)
pen.pendown()
pen.color("red")
pen.begin_fill()
pen.forward(80)
pen.left(90)
pen.forward(20)
pen.left(90)
pen.forward(80)
pen.left(90)
pen.forward(20)
pen.end_fill()
# 绘制雪人的围巾
pen.penup()
pen.goto(-40, 70)
pen.pendown()
pen.color("green")
pen.begin_fill()
pen.forward(80)
pen.right(90)
pen.forward(20)
pen.right(90)
pen.forward(80)
pen.right(90)
pen.forward(20)
pen.end_fill()
# 绘制雪人的手臂
pen.penup()
pen.goto(-60, 30)
pen.pendown()
pen.color("brown")
pen.pensize(5)
pen.setheading(180)
pen.forward(40)
pen.penup()
pen.goto(60, 30)
pen.pendown()
pen.setheading(0)
pen.forward(40)
# 隐藏画笔
pen.hideturtle()
# 结束绘制
turtle.done()
```
阅读全文