Python中的turtle.shearfactor()函数
turtle模块以面向对象和面向过程的方式提供Turtle图形基元。因为它使用 Tkinter 作为底层图形,它需要安装一个支持 Tk 的 Python 版本。
turtle.shearfactor()
该函数用于设置或返回当前的剪切系数。它根据给定的剪切系数剪切龟形,也就是剪切角度的正切值剪切龟形。
语法: turtle.shearfactor(shear=None)
参数:
shear(可选):数,剪切角的正切。
下面是上述方法的实现和一些例子。
例子1 :
# 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)
输出 :
例子2 :
# 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)
输出 :