python画一棵树源代码_Python+Turtle动态绘制一棵树实例分享
本文实例主要是对turtle的使用,实现Python+turtle动态绘制一棵树的实例,具体代码:
# drawtree.py
from turtle import Turtle, mainloop
def tree(plist, l, a, f):
""" plist is list of pens
l is length of branch
a is half of the angle between 2 branches
f is factor by which branch is shortened
from level to level."""
if l > 5: #
lst = []
for p in plist:
p.forward(l)#沿着当前的方向画画Move the turtle forward by the specified distance, in the direction the turtle is headed.
q = p.clone()#Create and return a clone of the turtle with same position, heading and turtle properties.
p.left(a) #Turn turtle left by angle units
q.right(a)# turn turtle right by angle units, nits are by default degrees, but can be set via the degrees() and radians() functions.
lst.append(p)#将元素增加到列表的最后
lst.append(q)
tree(lst, l*f, a, f)
def main():
p = Turtle()
p.color("green")
p.pensize(5)
#p.setundobuffer(None)
p.hideturtle() #Make the turtle invisible. It's a good idea to do this while you're in the middle of doing some complex drawing,
#because hiding the turtle speeds up the drawing observably.
#p.speed(10)
# p.getscreen().tracer(1,0)#Return the TurtleScreen object the turtle is drawing on.
p.speed(10)
#TurtleScreen methods can then be called for that object.
p.left(90)# Turn turtle left by angle units. direction 调整画笔
p.penup() #Pull the pen up – no drawing when moving.
p.goto(0,-200)#Move turtle to an absolute position. If the pen is down, draw line. Do not change the turtle's orientation.
p.pendown()# Pull the pen down – drawing when moving. 这三条语句是一个组合相当于先把笔收起来再移动到指定位置,再把笔放下开始画
#否则turtle一移动就会自动的把线画出来
#t = tree([p], 200, 65, 0.6375)
t = tree([p], 200, 65, 0.6375)
main()
实现效果:
总结
以上就是本文关于Python+Turtle动态绘制一棵树实例分享的全部内容,希望对大家有所帮助。感兴趣的朋友可以继续参阅本站其他相关专题,如有不足之处,欢迎留言指出。感谢朋友们对本站的支持!
python画一棵树源代码_Python+Turtle动态绘制一棵树实例分享相关推荐
- 用python画树_Python+Turtle动态绘制一棵树实例分享
本文实例主要是对turtle的使用,实现Python+turtle动态绘制一棵树的实例,具体代码: # drawtree.py from turtle import Turtle, mainloop ...
- python 画八角形_GitHub - xuedengyue/Turtle_Drawing: 利用Turtle递归绘制分形几何图形
Turtle_Drawing 利用Turtle递归绘制分形几何图形 一.Turtle的常用方法 方法 描述 turtle.forward(distance) 向当前画笔方向移动distance像素长度 ...
- python画的图怎么保存_python通过PyGame绘制图像并保存为图片文件的代码
把开发过程中常用的一些内容片段记录起来,下边内容是关于python通过PyGame绘制图像并保存为图片文件的内容,希望对大伙有较大好处. ''' pg_draw_circle_save101.py d ...
- python画螺旋状图形教程_Python实现的绘制三维双螺旋线图形功能示例
本文实例讲述了Python实现的绘制三维双螺旋线图形功能.分享给大家供大家参考,具体如下: 代码: # -*- coding:utf-8 -*- #! python3 #绘制三维双螺旋线 import ...
- python画同心圆循环源代码_Python Turtle:使用circle()方法绘制同心圆
我展示了用Python的Turtle模块绘制的孙子图案, 他要求看同心圆. 我以为用乌龟的circle()画它们会更快 而不是编写自己的代码来生成一个圆.哈!我被困住了. 我看到产生的圆圈开始在乌龟的 ...
- python turtle画四叶草的步骤_python turtle工具绘制四叶草的实例分享
本篇文章介绍了python使用turtle库绘制四叶草的方法,代码很简单,希望对学习python的朋友有帮助. import turtle import time turtle.setup(650., ...
- python turtle画有趣的图形_Python turtle库绘制简单图形
一.简介 Python中的turtle库是一个直观有趣的图形绘制函数库.turtle库绘制图形有一个基本框架:一个小海龟在坐标系中爬行,其爬行轨迹形成了绘制图形. 二.简单的图形列举 1.绘制4个不同 ...
- python绘制若干颜色的菱形_Python turtle库绘制菱形的3种方式小结
Python turtle库绘制菱形的3种方式小结 绘制一个菱形四边形,边长为 200 像素.方法1和2绘制了内角为60和120度的菱形,方法3绘制了内角为90度的菱形. 方法1 ...
- 用python画小动物大全_python3用turtle库进行绘制小猪佩奇图案
晚上闲着无事,深入学习这个turtle用法,就做了小猪佩奇图 附上代码: # coding: utf-8 #功能:绘画小猪佩奇 import turtle as t t.screensize(400, ...
最新文章
- 【技术交流】让我们来谈一谈多线程和并发任务
- 从算法到硬件,一文读懂2019年 AI如何演进
- 虚拟化基础架构Windows 2008篇之8-添加启动映像
- android clipdrawable 小例子
- python流程控制语句-Python_流程控制语句
- windows下配置mysql数据库_mysql数据库1-windows下mysql安装及配置
- Qt Creator编辑2D内容
- P1955 [NOI2015]程序自动分析 离散化学习 lower_bound学习
- iOS开发之网络编程--6、NSURLSessionConfiguration笔记
- npm 更换插件版本_Node CLI 工具的插件方案探索
- OpenShift / RHEL / DevSecOps 汇总目录
- 网络打印机 RPC服务器不可用
- mysql备份的sql语句_Mysql主从备份和SQL语句的备份
- spring任务调度的使用
- 嵌入式软件开发是什么?
- 废柴日记之中秋特辑:那些年我们一直分不清楚的近义词们①
- plsql 导入导出数据
- 利用pl/sql读文件(简单)
- PageHelper.startPage的使用
- CSP-S2022游记