本文实例主要是对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动态绘制一棵树实例分享相关推荐

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

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

  2. python 画八角形_GitHub - xuedengyue/Turtle_Drawing: 利用Turtle递归绘制分形几何图形

    Turtle_Drawing 利用Turtle递归绘制分形几何图形 一.Turtle的常用方法 方法 描述 turtle.forward(distance) 向当前画笔方向移动distance像素长度 ...

  3. python画的图怎么保存_python通过PyGame绘制图像并保存为图片文件的代码

    把开发过程中常用的一些内容片段记录起来,下边内容是关于python通过PyGame绘制图像并保存为图片文件的内容,希望对大伙有较大好处. ''' pg_draw_circle_save101.py d ...

  4. python画螺旋状图形教程_Python实现的绘制三维双螺旋线图形功能示例

    本文实例讲述了Python实现的绘制三维双螺旋线图形功能.分享给大家供大家参考,具体如下: 代码: # -*- coding:utf-8 -*- #! python3 #绘制三维双螺旋线 import ...

  5. python画同心圆循环源代码_Python Turtle:使用circle()方法绘制同心圆

    我展示了用Python的Turtle模块绘制的孙子图案, 他要求看同心圆. 我以为用乌龟的circle()画它们会更快 而不是编写自己的代码来生成一个圆.哈!我被困住了. 我看到产生的圆圈开始在乌龟的 ...

  6. python turtle画四叶草的步骤_python turtle工具绘制四叶草的实例分享

    本篇文章介绍了python使用turtle库绘制四叶草的方法,代码很简单,希望对学习python的朋友有帮助. import turtle import time turtle.setup(650., ...

  7. python turtle画有趣的图形_Python turtle库绘制简单图形

    一.简介 Python中的turtle库是一个直观有趣的图形绘制函数库.turtle库绘制图形有一个基本框架:一个小海龟在坐标系中爬行,其爬行轨迹形成了绘制图形. 二.简单的图形列举 1.绘制4个不同 ...

  8. python绘制若干颜色的菱形_Python turtle库绘制菱形的3种方式小结

    Python turtle库绘制菱形的3种方式小结 绘制一个菱形四边形,边长为 200 像素.方法1和2绘制了内角为60和120度的菱形,方法3绘制了内角为90度的菱形. 方法1‪‬‪‬‪‬‪‬‪‬‮ ...

  9. 用python画小动物大全_python3用turtle库进行绘制小猪佩奇图案

    晚上闲着无事,深入学习这个turtle用法,就做了小猪佩奇图 附上代码: # coding: utf-8 #功能:绘画小猪佩奇 import turtle as t t.screensize(400, ...

最新文章

  1. 【技术交流】让我们来谈一谈多线程和并发任务
  2. 从算法到硬件,一文读懂2019年 AI如何演进
  3. 虚拟化基础架构Windows 2008篇之8-添加启动映像
  4. android clipdrawable 小例子
  5. python流程控制语句-Python_流程控制语句
  6. windows下配置mysql数据库_mysql数据库1-windows下mysql安装及配置
  7. Qt Creator编辑2D内容
  8. P1955 [NOI2015]程序自动分析 离散化学习 lower_bound学习
  9. iOS开发之网络编程--6、NSURLSessionConfiguration笔记
  10. npm 更换插件版本_Node CLI 工具的插件方案探索
  11. OpenShift / RHEL / DevSecOps 汇总目录
  12. 网络打印机 RPC服务器不可用
  13. mysql备份的sql语句_Mysql主从备份和SQL语句的备份
  14. spring任务调度的使用
  15. 嵌入式软件开发是什么?
  16. 废柴日记之中秋特辑:那些年我们一直分不清楚的近义词们①
  17. plsql 导入导出数据
  18. 利用pl/sql读文件(简单)
  19. PageHelper.startPage的使用
  20. CSP-S2022游记

热门文章

  1. 为三角面片加上重心和在Matlab上绘制
  2. Java 基础进阶篇(四):抽象类与模板方法设计模式
  3. HttpUnit爬取中国知网特定大学网页
  4. Eclipse Marketplace( 插件市场 )集成插件方案
  5. 启明云端分享|ESP32-CAM操作教程
  6. ResNet与ResNeXt
  7. 海纳“千川”:得物多场景统一推荐平台|精选
  8. 微信公众号 接口配置信息 URL 配置失败(能进入后台方法,无返回信息)
  9. Ubuntu16.04 安装搜狗输入法后 键盘符号不对应的问题
  10. 【Diary】2023·七月