As a non famous and non professional painter in the world , Of course, let's enjoy my masterpiece of the century first :

Of course, a well-known painter must master different painting styles , Now let's enjoy another masterpiece of mine ：

as everyone knows , As a programmer , Of course not a cripple , The hand speed gained by tapping the keyboard day and night and going to the toilet at night , It's not a minute to draw such a cherry tree ? This cherry tree , We used python of turtle modular , Using some mathematical functions , Randomly draw different branches and falling petals , Each time we run, we generate a relatively unique tree （ If the random numbers are not the same ）. No more nonsense , Look at the source code ：

import turtle

from random import *

from math import *

def tree(n, l):

turtle.pendown()

turtle.pencolor(t, t, t)

turtle.pensize(n / 3)

turtle.forward(l)

if n > 0:

b = random() * 15 + 10

c = random() * 15 + 10

d= l * (random() * 0.25 + 0.7)

turtle.right(b)

tree(n - 1, d)

turtle.left(b + c)

tree(n - 1, d)

turtle.right(c)

else:

turtle.right(90)

turtle.pencolor(n, n*0.8, n*0.8)

turtle.circle(3)

turtle.left(90)

z=random()

if z>0.7:

turtle.up()

an = -40 + random()*40

dis = int(800*random()*0.5 + 400*random()*0.3 + 200*random()*0.2)

turtle.forward(dis)

turtle.down()

turtle.right(90)

turtle.pencolor(n*0.5+0.5, 0.4+n*0.4, 0.4+n*0.4)

turtle.circle(2)

turtle.left(90)

turtle.up()

turtle.backward(dis)

turtle.up()

turtle.backward(l)

turtle.bgcolor(0.5, 0.5, 0.5) # Background color

turtle.hideturtle() # hide turtle

turtle.speed(0) # speed ,1-10 gradual ,0 Fastest

turtle.tracer(0, 0)

turtle.up() # pen-up

turtle.backward(100)

turtle.left(90) # Turn left 90 degree

turtle.up() # pen-up

turtle.backward(300) # back off 300

tree(12, 100) # recursion 7 layer

turtle.done()

Technology
Daily Recommendation
views 2