Home >Backend Development >Python Tutorial >python实现绘制树枝简单示例

python实现绘制树枝简单示例

WBOY
WBOYOriginal
2016-06-16 08:43:041505browse

python是解释型语言,本文介绍了Python下利用turtle实现绘图功能的示例,本例所示为Python绘制一个树枝,具体实现代码如下:
    

python是解释型语言,本文介绍了Python下利用turtle实现绘图功能的示例,本例所示为Python绘制一个树枝,具体实现代码如下:
   
import turtle
def branch(length,level):
  if level<=0:
    return
 
  turtle.forward(length)
  turtle.left(45)
  branch(0.6*length,level-1)
  turtle.right(90)
  branch(0.6*length,level-1)
  turtle.left(45)
  turtle.backward(length)
  return
 
turtle.left(90)
branch(100,6)

效果图如下:

效果图如下:

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn