📜  Python中的 turtle.fillcolor()函数

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

Python中的 turtle.fillcolor()函数

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

乌龟.fillcolor()

此方法用于返回或设置填充颜色。如果turtleshape 是一个多边形,该多边形的内部将使用新设置的填充颜色进行绘制。

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

示例 1:

Python3
# importing package
import turtle
  
# set turtle
turtle.shape("turtle")
turtle.turtlesize(3,3,1)
  
# check by default value
print(turtle.fillcolor())
  
# set blue color
turtle.fillcolor("blue")
  
# check fillcolor value
print(turtle.fillcolor())


Python3
# importing package
import turtle
  
# method to draw a star
def star():
    for i in range(5):
        turtle.forward(60)
        turtle.right(144)
  
# method to set position
# and fill color in star
def draw(x,y,col):
    turtle.up()
    turtle.setpos(x,y)
    turtle.down()
    turtle.fillcolor(col)
    turtle.begin_fill()
    star()
    turtle.end_fill()
  
# Driver Code
draw(-100,0,"red")
draw(-50,0,"yellow")
draw(0,0,"blue")
draw(50,0,"green")
  
# hide the turtle
turtle.hideturtle()


输出 :

black
blue

示例 2:

Python3

# importing package
import turtle
  
# method to draw a star
def star():
    for i in range(5):
        turtle.forward(60)
        turtle.right(144)
  
# method to set position
# and fill color in star
def draw(x,y,col):
    turtle.up()
    turtle.setpos(x,y)
    turtle.down()
    turtle.fillcolor(col)
    turtle.begin_fill()
    star()
    turtle.end_fill()
  
# Driver Code
draw(-100,0,"red")
draw(-50,0,"yellow")
draw(0,0,"blue")
draw(50,0,"green")
  
# hide the turtle
turtle.hideturtle()

输出 :