Python中的 turtle.shearfactor()函数
turtle 模块以面向对象和面向过程的方式提供海龟图形原语。因为它使用 Tkinter 作为底层图形,所以它需要安装一个支持 Tk 的Python版本。
海龟.shearfactor()
该函数用于设置或返回当前剪切因子。它根据给定的剪切因子剪切海龟形状,它是剪切角的正切。
Syntax : turtle.shearfactor(shear=None)
Parameter:
shear(optional): number, tangent of the shear angle.
以下是上述方法的实现以及一些示例:
示例 1:
Python3
# importing package
import turtle
# set turtle
turtle.speed(1)
turtle.shape("turtle")
turtle.up()
turtle.goto(-150,0)
turtle.down()
# forward turtle by 100
turtle.forward(100)
# set shear by +ive value
turtle.shearfactor(0.2)
# forward turtle by 100
turtle.forward(100)
# set shear by -ive value
turtle.shearfactor(-0.2)
# forward turtle by 100
turtle.forward(100)
Python3
# importing package
import turtle
# set turtle
turtle.speed(1)
turtle.up()
turtle.goto(-40,40)
turtle.down()
# set shear and apply to
# all shapes
turtle.shearfactor(0.5)
# get shape
sh=turtle.getshapes()
# loop for pattern
for i in range(len(sh)):
turtle.shape(sh[i])
turtle.forward(100+10*i)
turtle.right(90)
turtle.forward(100+10*i)
turtle.right(90)
输出 :
示例 2:
Python3
# importing package
import turtle
# set turtle
turtle.speed(1)
turtle.up()
turtle.goto(-40,40)
turtle.down()
# set shear and apply to
# all shapes
turtle.shearfactor(0.5)
# get shape
sh=turtle.getshapes()
# loop for pattern
for i in range(len(sh)):
turtle.shape(sh[i])
turtle.forward(100+10*i)
turtle.right(90)
turtle.forward(100+10*i)
turtle.right(90)
输出 :