如何用python画圣诞树
时间: 2023-03-25 18:01:24 浏览: 116
你可以使用Python中的turtle库来画圣诞树。以下是一个简单的代码示例:
```python
import turtle
# 设置画布大小和背景色
turtle.setup(800, 600)
turtle.bgcolor('black')
# 画圣诞树
turtle.color('green')
turtle.speed()
turtle.penup()
turtle.goto(, -200)
turtle.pendown()
turtle.begin_fill()
turtle.circle(200)
turtle.end_fill()
turtle.color('yellow')
turtle.penup()
turtle.goto(-100, 100)
turtle.pendown()
turtle.begin_fill()
turtle.circle(50)
turtle.end_fill()
turtle.penup()
turtle.goto(100, 100)
turtle.pendown()
turtle.begin_fill()
turtle.circle(50)
turtle.end_fill()
turtle.penup()
turtle.goto(, 150)
turtle.pendown()
turtle.color('red')
turtle.begin_fill()
turtle.circle(30)
turtle.end_fill()
# 显示画布
turtle.done()
```
运行代码后,你将会看到一个绿色的圆形,上面有两个黄色的圆圈和一个红色的圆圈,就像一个圣诞树一样。
阅读全文
相关推荐















