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

python实现绘制树枝简单示例

WBOY
Release: 2016-06-16 08:43:04
Original
1499 people have browsed it

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)

效果图如下:
Copy after login

效果图如下:

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template