2020/02/25
python使用turtle繪製分形樹
效果如下:
3功能:利用遞迴繪製分型樹
4版本:1.0
5日期:2020/02/25
6'''78
import
turtle910
defdraw_branch(branch_length):
11'''
12繪製分型樹
13:param branch_length:
14:return:
15'''
16if branch_length > 5:
17if branch_length > 10:
18 turtle.pensize(10)
19 turtle.color('
brown')
20else
:21 turtle.pensize(5)
22 turtle.color('
green')
2324
#繪製右側樹枝
25turtle.forward(branch_length)
2627
28print('向前'
,branch_length)
29 turtle.right(20)
30print('
右轉 20')
31 draw_branch(branch_length-15)
3233
#繪製左側樹枝
34 turtle.left(40)
35print('
左轉 40')
36 draw_branch(branch_length-15)
3738
#返回之前的樹枝上
39print('
右轉 20')
40 turtle.right(20)
4142
turtle.penup()
43turtle.backward(branch_length)
44turtle.pendown()
4546
print('向後'
,branch_length)
4748
defmain():
49'''
50主函式
51'''
52 turtle.left(90)
53turtle.penup()
54 turtle.backward(200)
55turtle.pendown()
56 turtle.color('
brown')
57print('
左轉 90')
58 turtle.speed(5000)
59 draw_branch(100);
60 turtle.exitonclick()
6162
if__name__ == '
__main__':
63 main()
python 使用 vtkPolyData 繪線
vtk 可以通過vtkpolydata 繪製曲線以及三角麵片,下面的 簡單的繪製乙個線。使用到如下 vtk的類 如下 import vtk import numpy as np class ployline vtk.vtkobject 繪製中心線 def init self 構造2d的線 self....
Python中turtle庫的使用
turtle庫是python內建的圖形化模組,屬於標準庫之一,位於python安裝目錄的lib資料夾下,常用函式有以下幾種 coding utf 8 繪製蟒蛇 import turtle turtle.penup turtle.pencolor red turtle.forward 250 turt...
Python 使用turtle繪製多重巢狀的六邊形
import turtle import math import numpy as np 設定turtle,及定義顏色表 turtle.pensize 1 設定線的粗細 turtle.shape turtle 設定turtle形狀 colors red yellow green blue black...