python海龟绘图画圣诞树
时间: 2023-12-25 19:30:01 浏览: 85
Python 使用海龟(turtle)模块绘制圣诞树 Python源码
以下是使用turtle库绘制圣诞树的Python代码示例:
```python
import turtle
# 设置画布和画笔
canvas = turtle.Screen()
canvas.bgcolor("white")
pen = turtle.Turtle()
pen.speed(1)
# 绘制树干
pen.color("brown")
pen.goto(0, -200)
pen.setheading(90)
pen.forward(200)
# 绘制树叶
pen.color("green")
pen.begin_fill()
pen.setheading(0)
pen.goto(-100, -200)
pen.goto(100, -200)
pen.goto(0, 0)
pen.end_fill()
# 绘制装饰品
pen.color("red")
pen.penup()
pen.goto(-50, 50)
pen.pendown()
pen.begin_fill()
pen.circle(20)
pen.end_fill()
pen.penup()
pen.goto(50, 50)
pen.pendown()
pen.begin_fill()
pen.circle(20)
pen.end_fill()
pen.penup()
pen.goto(0, 100)
pen.pendown()
pen.begin_fill()
pen.circle(20)
pen.end_fill()
# 绘制星星
pen.color("yellow")
pen.penup()
pen.goto(-10, 150)
pen.pendown()
pen.begin_fill()
for _ in range(5):
pen.forward(30)
pen.right(144)
pen.end_fill()
# 结束绘制
pen.hideturtle()
canvas.exitonclick()
```
阅读全文