Python画樱花树 !
Python的turtle模块肯定很棒吧!这次,我们要利用turtle来完成一个樱花树的绘制。我们要用def和for语句循环。 难度等级: Python资源共享群:626017123 工具:turtle、random 我用的是Python 3.8.0b3 Shell,开始写代码吧! # 樱花树 import randomimport turtle Jess = turtle.Turtle()Jess.hideturtle()Jess.left(90)Jess.penup()Jess.goto(0, -100)Jess.pendown() # “画树”函数# 参数分别是树枝长度、画笔def tree(branchLen, t): if (branchLen > 3): if (8 <= branchLen and branchLen <= 12) : if (random.randint(0, 2) == 0) : Jess.pencolor('snow') else : Jess.pencolor('lightcoral') Jess.pensize((branchLen / 3)) elif (branchLen < 8) : if (random.randint(0, 1) == 0) : Jess.pencolor('snow') else : Jess.pencolor(