turtle 模塊以麵向對象和麵向過程的方式提供 turtle 圖形基元。由於它使用Tkinter作為基礎圖形,因此需要安裝有Tk支持的Python版本。
turtle .shapetransform()
此函數用於設置或返回 turtle 形狀的當前變換矩陣。如果沒有給出任何矩陣元素,則返回轉換矩陣。否則,設置給定元素並根據第一行t11,t12和second-row t21、22組成的矩陣變換 turtle 形狀。
用法:turtle.shapetransform(t11=None, t12=None, t21=None, t22=None)
參數:
t11,t12,t21,t22(可選):行列式t11 * t22-t12 * t21不能為零,否則會引起錯誤。
下麵是上述方法的實現和一些示例:
範例1:
Python3
# import package
import turtle
# check the default value
print(turtle.shapetransform())
輸出:
(1.0, 0.0, 0.0, 1.0)
範例2:
Python3
# import package
import turtle
# change shapetransform to 2,0,2,0
# as determinant of the matrix
# [[2,0],[0,2]] is 0.
# so, raised an error
turtle.shapetransform(2,0,2,0)
輸出:
turtle.TurtleGraphicsError:Bad shape transform matrix:must not be singular
範例3:
Python3
# import package
import turtle
# loop for pattern
for i in range(5):
for j in range(10):
# motion
turtle.forward(5+5*(i+j))
turtle.left(45)
# transform the shape
turtle.shapetransform(i+1,0,0,i+1)
輸出:
相關用法
- Python Wand function()用法及代碼示例
- Python str()用法及代碼示例
- Python hex()用法及代碼示例
- Python id()用法及代碼示例
- Python int()用法及代碼示例
- Python now()用法及代碼示例
- Python cmp()用法及代碼示例
- Python oct()用法及代碼示例
- Python dir()用法及代碼示例
- Python map()用法及代碼示例
- Python tell()用法及代碼示例
- Python sum()用法及代碼示例
- Python ord()用法及代碼示例
- Python __import__()用法及代碼示例
- Python numpy.ix_()用法及代碼示例
- Python numpy.ma.where()用法及代碼示例
注:本文由純淨天空篩選整理自deepanshu_rustagi大神的英文原創作品 turtle.shapetransform() function in Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。