python樱花树代码大全
时间: 2023-11-10 12:03:45 浏览: 108
以下是一个绘制樱花树的Python代码示例:
```python
import turtle
import random
def draw_tree(t, branch_len):
angle = random.randint(22, 30)
sf = random.uniform(0.6, 0.8)
if branch_len < 5:
t.color("green")
else:
t.color("brown")
if branch_len > 15:
t.pensize(int(branch_len / 10))
else:
t.pensize(2)
if branch_len > 3:
t.forward(branch_len)
t.right(angle)
draw_tree(t, branch_len * sf)
t.left(angle * 2)
draw_tree(t, branch_len * sf)
t.right(angle)
t.backward(branch_len)
def draw_sakura():
window = turtle.Screen()
window.bgcolor("white")
t = turtle.Turtle()
t.speed(0)
t.up()
t.goto(0, -200)
t.down()
draw_tree(t, 100)
window.exitonclick()
draw_sakura()
```
阅读全文