python用函数画雪人
时间: 2023-08-13 16:05:39 浏览: 216
Python高级炫酷爱心代码.txt
当然可以!以下是用Python函数绘制雪人的示例代码:
```python
import turtle
def draw_circle(color, radius, x, y):
turtle.penup()
turtle.fillcolor(color)
turtle.goto(x, y)
turtle.pendown()
turtle.begin_fill()
turtle.circle(radius)
turtle.end_fill()
def draw_snowman():
turtle.speed(10)
# 绘制雪人的身体
draw_circle("white", 30, 0, -40)
draw_circle("white", 40, 0, -100)
draw_circle("white", 60, 0, -200)
# 绘制雪人的眼睛
draw_circle("black", 2, -10, -10)
draw_circle("black", 2, 10, -10)
# 绘制雪人的嘴巴
turtle.penup()
turtle.goto(-15, -15)
turtle.pendown()
turtle.right(90)
turtle.circle(15, 180)
# 绘制雪人的帽子
turtle.fillcolor("red")
turtle.penup()
turtle.goto(-35, 8)
turtle.pendown()
turtle.forward(70)
turtle.left(120)
turtle.forward(100)
turtle.left(120)
turtle.forward(100)
turtle.left(120)
turtle.forward(70)
turtle.hideturtle()
turtle.done()
# 调用函数绘制雪人
draw_snowman()
```
运行以上代码,将会在窗口中绘制一个雪人。你可以根据需要调整绘制的位置、颜色和大小等参数。希望对你有所帮助!
阅读全文