大家好,本文将围绕python画樱花树代码如何读懂展开说明,如何用python画一朵樱花是一个很多人都想弄明白的事情,想搞清楚pythonturtle绘图代码樱花需要先了解以下几个事情。
提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
文章目录
- 前言
- turtle是什么
- 步骤
- 总结
前言
今天我要用Python的turtle函数库来编一个樱花树代码
还用到Python的random随机函数
一、turtle是什么?
turtle 是Python的一种工具,该工具是用来画图的。
random是Python的一个随机数生成的工具Python中Turtle画蝴蝶。
二、使用步骤
1.引入库
代码如下:
from import turtle *import random
2.剩余代码
代码如下:
import random tracer(0) setup(800,800) up() goto(0,-400) left(90) down() pensize(20) shuColor="tomato3" guanColor="MediumPurple2" bgcolor("lightblue") color(shuColor) fd(300) def twoTree(level,chang,jiao,size): if level==0: return if level<=3: color(guanColor) else: color(shuColor) pensize(size) lt(jiao/2) fd(chang) twoTree(level-1,chang*(random.randint(6,10)/10),jiao*0.9,size*0.6) up() bk(chang) rt(jiao/2) down() if level<=3: color(guanColor) else: color(shuColor) pensize(size) rt(jiao/2) fd(chang) twoTree(level-1,chang*(random.randint(6,10)/10),jiao*0.9,size*0.6) up() bk(chang) down() lt(jiao/2) twoTree(12,100,60,20*0.6)
总结
以上就是今天的Python画图内容。谢谢大家!