📜  Python中的 turtle.color() 方法

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

Python中的 turtle.color() 方法

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

乌龟.颜色()

此方法用于更改海龟的颜色。默认颜色为黑色。

句法:

turtle.color(*args)

参数:

Format Arguments Description
 turtle.color( colorstring ) colorstring A string of color name like “red”, “green”, etc.
 turtle.color( (r, g, b) )  (r, g, b) A tuple of three values r, g, and b using rgb color code
 turtle.color( r, g, b ) r, g, b Three values r, g, and b using rgb color code

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

示例 1:

Python3
# importing package
import turtle
 
 
# use forward by 50 (default = black)
turtle.forward(50)
 
# change the color of turtle
turtle.color("red")
 
# use forward by 50 (color = red)
turtle.forward(50)


Python3
# importing package
import turtle
 
 
# use forward by 100 (default = black)
turtle.forward(100)
 
# change the color of turtle
turtle.color("red")
 
# use forward by 100 in 90 degrees
# right (color = red)
turtle.right(90)
turtle.forward(100)
 
# change the color of turtle
turtle.color((41,41,253))
 
# use forward by 100 in 90 degrees
# right (color = blue)
turtle.right(90)
turtle.forward(100)
 
# change the color of turtle
turtle.color(41,253,41)
 
# use forward by 100 in 90 degrees
# right (color = green)
turtle.right(90)
turtle.forward(100)



输出 :

示例 2:

Python3

# importing package
import turtle
 
 
# use forward by 100 (default = black)
turtle.forward(100)
 
# change the color of turtle
turtle.color("red")
 
# use forward by 100 in 90 degrees
# right (color = red)
turtle.right(90)
turtle.forward(100)
 
# change the color of turtle
turtle.color((41,41,253))
 
# use forward by 100 in 90 degrees
# right (color = blue)
turtle.right(90)
turtle.forward(100)
 
# change the color of turtle
turtle.color(41,253,41)
 
# use forward by 100 in 90 degrees
# right (color = green)
turtle.right(90)
turtle.forward(100)


输出 :