本文实例主要是对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利用turtle库绘制彩虹代码示例

Python使用Turtle模块绘制五星红旗代码示例

Python内置模块turtle绘图详解

Python中turtle作图示例

使用Python的turtle模块画图的方法

python 简单的绘图工具turtle使用详解

时间: 2018-01-13

用python画树_Python+Turtle动态绘制一棵树实例分享相关推荐

  1. python画一棵树源代码_Python+Turtle动态绘制一棵树实例分享

    本文实例主要是对turtle的使用,实现Python+turtle动态绘制一棵树的实例,具体代码: # drawtree.py from turtle import Turtle, mainloop ...

  2. 用python画大白_Python turtle 画个大白

    今天用Python Turtle画个大白吧.效果图如下: Python画大白def bai(): #tracer(False) speed(0) pensize(5) color('black','w ...

  3. python画彩色螺旋线_Python turtle 绘制彩色螺旋线

    小朋友总会别各种五颜六色的色彩所吸引,就拿小编的小侄子来说,自己很喜欢美术课,看到五颜六色的颜色都想尝试着图一下,但结果总是不仅人意,今天南京小码王Python培训机构,就为大家介绍一下Python ...

  4. 用python画漫画_Python——turtle绘制动漫形象(魔法少女小圆晓美焰,super beautiful)...

    import turtle as te import time WriteStep = 15 # 贝塞尔函数的取样次数 Speed = 5 Width = 600 # 界面宽度 Height = 50 ...

  5. python画卡通_Python——turtle绘制动漫形象(魔法少女小圆晓美焰,super beautiful)...

    import turtle as te import time WriteStep = 15 # 贝塞尔函数的取样次数 Speed = 5 Width = 600 # 界面宽度 Height = 50 ...

  6. python画蛋糕_python+turtle制作一个生日蛋糕

    话不多说,直接上代码 import turtle as t import time t.fillcolor("#FFFFCC") t.begin_fill() t.penup() ...

  7. 用python画一箭穿心_python turtle画一箭穿心

    有个全套的,你自已你修改下(来源:https://blog.csdn.net/superstar_zbt/article/details/87307519) #coding utf-8 import ...

  8. python画小汽车_Python语言怎么画小红花?

    可以用python内置的turtle库绘制 ,很简单但是功能很强大 绘制小红花代码如下 import turtle import math def p_line(t, n, length, angle ...

  9. python画轨迹曲线-python 画3维轨迹图并进行比较的实例

    一. 数据的格式 首先我们需要x,y,z三个数据进行画图.从本实验用到的数据集KITTI 00.txt中举例: 1.000000e+00 9.043680e-12 2.326809e-11 5.551 ...

最新文章

  1. r语言 整理、处理数据步骤_R语言万能数据清洗整理包Tidyverse(一)
  2. 信息系统项目管理师-论文要求
  3. 批量修改数据_#泰Q头条#065期 四步搞定Excel表中的批量数据修改
  4. asp.net mvc 应用Bundle(捆绑和微小)压缩技术 启用 BundleConfig 配置web.config
  5. 超经典的Android开源项目
  6. C语言变量长度在32位和64位处理器上的关系
  7. dede php标签 value=$v,dede:php标签是什么
  8. 21天学通Java调用不存在的对象或成员变量
  9. boost::enable_shared_from_this<T>用途
  10. 【截屏篇】系统PrtSc
  11. 霹雳吧啦Wz语义分割学习笔记P1
  12. DQ77KB刷bios工程小记-old文章备份
  13. 郑州大学计算机专业国际学院,郑州大学国际学院怎么样?郑州大学国际学院好吗?(历年分数、专业设置、校园环境、教学实力、名人校友) - 职友集...
  14. (80)FPGA减法器设计(全减法器)
  15. php后台界面修改教程,帝国cms后台界面修改方法
  16. 大学英语综合教程四 Unit 4 课文内容英译中 中英翻译
  17. 信捷触摸屏通讯示例1
  18. 划时代变革丨山石网科重磅发布A系列智能下一代防火墙 重新定义边界安全
  19. 怎么用c语言编写画图软件,大佬们,小菜鸟想问一问用vc编译器做简易画图软件...
  20. ICLR 2018 有什么值得关注的亮点?

热门文章

  1. asp.net core WebAPI实现CRUD
  2. Windows 容器
  3. MySQL用户及权限管理
  4. php获取邮箱内容吗,php正则验证email邮箱及抽取内容中email的例子
  5. ArcGIS实验教程——实验三十七:基于ArcGIS的太阳辐射分析案例教程
  6. 剑指offer之二叉搜索树和双向链表
  7. linux shell之替换目录下包含关键字所有文本里面的内容
  8. Android之在linux终端执行shell脚本文件(通过aapt)得到apk包名
  9. Android之android studio如何解决‘:app:packageDebug‘.(Duplicate files copied in APK META-INF/DEPENDENCIES)
  10. Git之如何解决sourceTree已经pull全部下来但是本地没有更新的问题