python海龟绘图 清明节
时间: 2023-10-19 15:07:09 浏览: 172
好的,我知道了。关于python海龟绘图清明节,可以画出一棵柳树和一些飞舞的柳絮,代码如下:
```python
import turtle
# 画柳树
def draw_tree():
turtle.color('green')
turtle.pensize(5)
turtle.penup()
turtle.goto(-200, -200)
turtle.pendown()
turtle.left(90)
turtle.forward(100)
draw_branch(80, 60, 0.6)
turtle.penup()
turtle.goto(-200, -200)
turtle.pendown()
draw_branch(80, 60, 0.6)
# 画树枝
def draw_branch(branch_length, angle, scale):
if branch_length > 5:
turtle.pensize(scale * 10)
turtle.forward(branch_length)
turtle.right(angle)
draw_branch(branch_length * scale, angle * 0.8, scale * 0.9)
turtle.left(angle * 2)
draw_branch(branch_length * scale, angle * 0.8, scale * 0.9)
turtle.right(angle)
turtle.backward(branch_length)
# 画柳絮
def draw_flower():
turtle.color('white')
turtle.penup()
turtle.goto(-200, 200)
turtle.pendown()
turtle.begin_fill()
turtle.circle(20)
turtle.end_fill()
# 主函数
def main():
turtle.speed(0)
draw_tree()
for i in range(10):
draw_flower()
turtle.right(36)
turtle.hideturtle()
turtle.done()
if __name__ == '__main__':
main()
```
阅读全文