📜  Python中的 turtle.turtlesize()函数

📅  最后修改于: 2022-05-13 01:55:02.282000             🧑  作者: Mango

Python中的 turtle.turtlesize()函数

turtle 模块以面向对象和面向过程的方式提供海龟图形原语。因为它使用 Tkinter 作为底层图形,所以它需要安装一个支持 Tk 的Python版本。

乌龟.turtlesize()

此函数用于返回或设置笔的属性 x 或 y 拉伸因子和轮廓。

句法 :

参数:

ArgumentsValue TypeDescription
stretch_widpositive numberstretchfactor perpendicular to orientation
stretch_lenpositive numberstretchfactor in direction of turtles orientation
outlinepositive numberdetermines the width of the shapes’s outline

以下是上述方法的实现以及一些示例:

示例 1:

Python3
# import package
import turtle
  
# set turtle
turtle.speed(1)
turtle.shape("turtle")
turtle.fillcolor("blue")
  
# loop for motion
for i in range(4):
    
    # set turtle width
    turtle.turtlesize(stretch_wid=(i+1)*0.5)
    turtle.forward(100)
    turtle.right(90)


Python3
# import package
import turtle
  
# set turtle
turtle.speed(1)
turtle.shape("turtle")
turtle.fillcolor("blue")
  
# loop for motion
for i in range(4):
  
    # set turtle length
    turtle.turtlesize(stretch_len=(i+1)*0.5)
    turtle.forward(100)
    turtle.right(90)


Python3
# import package
import turtle
  
# set turtle
turtle.speed(1)
turtle.shape("turtle")
turtle.fillcolor("blue")
  
# loop for motion
for i in range(4):
    
    # set turtle outline
    turtle.turtlesize(outline=i+1)
    turtle.forward(100)
    turtle.right(90)


Python3
# import package
import turtle
  
# set turtle
turtle.speed(1)
turtle.shape("turtle")
turtle.fillcolor("blue")
  
# loop for motion
for i in range(4):
    
    # set turtlesize properties all together
    turtle.turtlesize(stretch_wid=(i+1)*0.5,
                      stretch_len=(i+1)*0.5,
                      outline=(i+1)
                     )
    turtle.forward(100)
    turtle.right(90)


输出 :

示例 2:

Python3

# import package
import turtle
  
# set turtle
turtle.speed(1)
turtle.shape("turtle")
turtle.fillcolor("blue")
  
# loop for motion
for i in range(4):
  
    # set turtle length
    turtle.turtlesize(stretch_len=(i+1)*0.5)
    turtle.forward(100)
    turtle.right(90)

输出 :

示例 3:

Python3

# import package
import turtle
  
# set turtle
turtle.speed(1)
turtle.shape("turtle")
turtle.fillcolor("blue")
  
# loop for motion
for i in range(4):
    
    # set turtle outline
    turtle.turtlesize(outline=i+1)
    turtle.forward(100)
    turtle.right(90)

输出 :

示例 4:

Python3

# import package
import turtle
  
# set turtle
turtle.speed(1)
turtle.shape("turtle")
turtle.fillcolor("blue")
  
# loop for motion
for i in range(4):
    
    # set turtlesize properties all together
    turtle.turtlesize(stretch_wid=(i+1)*0.5,
                      stretch_len=(i+1)*0.5,
                      outline=(i+1)
                     )
    turtle.forward(100)
    turtle.right(90)

输出 :