Python画个圣诞老人
时间: 2023-12-25 11:30:34 浏览: 137
一个圣诞树的python源码-用python-画出
很高兴为您解答。下面是使用Python绘制圣诞老人的示例代码:
```python
import turtle
# 设置画布大小和背景颜色
turtle.setup(800, 600)
turtle.bgcolor("white")
# 设置画笔属性
turtle.pensize(3)
turtle.speed(1)
# 绘制圣诞老人的脸
turtle.penup()
turtle.goto(0, -100)
turtle.pendown()
turtle.circle(100)
# 绘制圣诞老人的帽子
turtle.fillcolor("red")
turtle.begin_fill()
turtle.goto(-50, 50)
turtle.goto(50, 50)
turtle.goto(0, 150)
turtle.end_fill()
# 绘制圣诞老人的眼睛
turtle.penup()
turtle.goto(-30, 80)
turtle.pendown()
turtle.fillcolor("black")
turtle.begin_fill()
turtle.circle(10)
turtle.end_fill()
turtle.penup()
turtle.goto(30, 80)
turtle.pendown()
turtle.fillcolor("black")
turtle.begin_fill()
turtle.circle(10)
turtle.end_fill()
# 绘制圣诞老人的鼻子
turtle.penup()
turtle.goto(0, 50)
turtle.pendown()
turtle.fillcolor("red")
turtle.begin_fill()
turtle.circle(10)
turtle.end_fill()
# 绘制圣诞老人的嘴巴
turtle.penup()
turtle.goto(-30, 20)
turtle.pendown()
turtle.circle(30, 180)
# 绘制圣诞老人的胡须
turtle.penup()
turtle.goto(-30, 20)
turtle.pendown()
turtle.goto(-70, 0)
turtle.penup()
turtle.goto(-30, 20)
turtle.pendown()
turtle.goto(-70, -20)
turtle.penup()
turtle.goto(-30, 20)
turtle.pendown()
turtle.goto(-70, -40)
turtle.penup()
turtle.goto(30, 20)
turtle.pendown()
turtle.goto(70, 0)
turtle.penup()
turtle.goto(30, 20)
turtle.pendown()
turtle.goto(70, -20)
turtle.penup()
turtle.goto(30, 20)
turtle.pendown()
turtle.goto(70, -40)
# 绘制圣诞老人的胡子
turtle.penup()
turtle.goto(-30, -20)
turtle.pendown()
turtle.goto(-70, -60)
turtle.penup()
turtle.goto(-30, -20)
turtle.pendown()
turtle.goto(-70, -80)
turtle.penup()
turtle.goto(30, -20)
turtle.pendown()
turtle.goto(70, -60)
turtle.penup()
turtle.goto(30, -20)
turtle.pendown()
turtle.goto(70, -80)
# 绘制圣诞老人的身体
turtle.penup()
turtle.goto(-50, -100)
turtle.pendown()
turtle.fillcolor("red")
turtle.begin_fill()
turtle.goto(50, -100)
turtle.goto(50, -200)
turtle.goto(-50, -200)
turtle.goto(-50, -100)
turtle.end_fill()
# 绘制圣诞老人的腿
turtle.penup()
turtle.goto(-50, -200)
turtle.pendown()
turtle.fillcolor("white")
turtle.begin_fill()
turtle.goto(-100, -300)
turtle.goto(0, -300)
turtle.goto(50, -200)
turtle.end_fill()
# 绘制圣诞老人的鞋子
turtle.penup()
turtle.goto(-100, -300)
turtle.pendown()
turtle.fillcolor("black")
turtle.begin_fill()
turtle.goto(0, -300)
turtle.goto(-50, -350)
turtle.goto(-100, -300)
turtle.end_fill()
turtle.penup()
turtle.goto(0, -300)
turtle.pendown()
turtle.fillcolor("black")
turtle.begin_fill()
turtle.goto(50, -350)
turtle.goto(0, -300)
turtle.end_fill()
# 绘制圣诞老人的手
turtle.penup()
turtle.goto(-50, -100)
turtle.pendown()
turtle.fillcolor("white")
turtle.begin_fill()
turtle.goto(-100, -150)
turtle.goto(-100, -200)
turtle.goto(-50, -200)
turtle.goto(-50, -100)
turtle.end_fill()
turtle.penup()
turtle.goto(50, -100)
turtle.pendown()
turtle.fillcolor("white")
turtle.begin_fill()
turtle.goto(100, -150)
turtle.goto(100, -200)
turtle.goto(50, -200)
turtle.goto(50, -100)
turtle.end_fill()
# 绘制圣诞老人的礼物
turtle.penup()
turtle.goto(-100, -200)
turtle.pendown()
turtle.fillcolor("green")
turtle.begin_fill()
turtle.goto(100, -200)
turtle.goto(100, -300)
turtle.goto(-100, -300)
turtle.goto(-100, -200)
turtle.end_fill()
turtle.penup()
turtle.goto(-100, -300)
turtle.pendown()
turtle.fillcolor("red")
turtle.begin_fill()
turtle.goto(100, -300)
turtle.goto(100, -350)
turtle.goto(-100, -350)
turtle.goto(-100, -300)
turtle.end_fill()
# 隐藏画笔
turtle.hideturtle()
# 结束绘制
turtle.done()
```
阅读全文