Python中的 turtle.mode()函数
turtle 模块以面向对象和面向过程的方式提供海龟图形原语。因为它使用 Tkinter 作为底层图形,所以它需要安装一个支持 Tk 的Python版本。
海龟.mode()
该函数用于设置海龟模式(“标准”、“标志”或“世界”)并执行重置。
Syntax : turtle.mode(mode=None)
Parameter:
mode: one of the strings ‘standard’, ‘logo’ or ‘world’
- Mode ‘standard’ is compatible with turtle.py.
- Mode ‘logo’ is compatible with most Logo-Turtle-Graphics.
- Mode ‘world’ uses userdefined ‘worldcoordinates’.
以下是上述方法的实现以及一些示例:
示例 1:
Python3
# importing package
import turtle
# check by default value
print(turtle.mode())
Python3
# importing package
import turtle
# motion with default mode (standard)
# default direction of turtle head
# is north in standard mode
turtle.forward(180)
# set mode to 'logo' mode
turtle.mode(mode='logo')
# do some motion
# default direction of turtle head
# is east in logo mode
turtle.forward(120)
# set mode to 'world' mode
turtle.mode(mode='world')
# do some motion
turtle.forward(100)
# set coordinates of the turtle
# mode (world) by choice of user
turtle.setworldcoordinates(-500,-500,500,500)
输出 :
standard
示例 2:
Python3
# importing package
import turtle
# motion with default mode (standard)
# default direction of turtle head
# is north in standard mode
turtle.forward(180)
# set mode to 'logo' mode
turtle.mode(mode='logo')
# do some motion
# default direction of turtle head
# is east in logo mode
turtle.forward(120)
# set mode to 'world' mode
turtle.mode(mode='world')
# do some motion
turtle.forward(100)
# set coordinates of the turtle
# mode (world) by choice of user
turtle.setworldcoordinates(-500,-500,500,500)
输出 :