python画满树樱花
时间: 2023-11-09 09:02:12 浏览: 98
要画满树樱花,可以使用Python的turtle库来实现。以下是一个简单的示例代码:
```python
import turtle
import random
def tree(branchLen, t):
if branchLen > 5:
angle = random.randint(20, 30)
sf = random.uniform(0.6, 0.8)
t.pensize(branchLen / 10)
t.forward(branchLen)
t.right(angle)
tree(branchLen * sf, t)
t.left(angle * 2)
tree(branchLen * sf, t)
t.right(angle)
t.backward(branchLen)
def petal(t):
for i in range(200):
radius = random.randint(20, 50)
x = random.randint(-300, 300)
y = random.randint(-200, 200)
t.penup()
t.goto(x, y)
t.pendown()
t.dot(radius, random.choice(['pink', 'lightpink', 'hotpink', 'deeppink', 'palevioletred', 'mediumvioletred']))
def main():
t = turtle.Turtle()
myWin = turtle.Screen()
t.left(90)
t.up()
t.backward(200)
t.down()
t.color("brown")
tree(100, t)
petal(t)
myWin.exitonclick()
main()
```
阅读全文