在 Python Turtle 中绘制颜色填充的形状

按照以下步骤绘制具有所需颜色的填充形状-

  1. 通过调用fillcolor()函数选择填充颜色并以#RRGGBB 格式传递颜色名称或颜色。
  2. 在第 1 步之后,您必须调用begin_fill()并使用 Turtle 函数开始绘图。完成绘图后,调用end_fill()函数以使用所选颜色填充绘制的图形。

在 Python Turtle 中绘制颜色填充的正方形

#Python program to draw color filled square in turtle programming
import turtle

t = turtle.Turtle()
t.fillcolor('blue')
t.begin_fill()
for i in range(4):
  t.forward(150)
  t.right(90)
t.end_fill()

上述程序的输出

Python Turtle 中的颜色填充方块

在 Python Turtle 中绘制颜色填充三角形

#Python program to draw color filled triangle in turtle programming
import turtle

t = turtle.Turtle()
t.fillcolor('#FFA500')
t.begin_fill()
for i in range(4):
  t.forward(150)
  t.right(-120)
t.end_fill()

上述程序的输出

Python Turtle 中的颜色填充三角形

在 Python Turtle 中绘制颜色填充的星星

#Python program to draw color filled star in turtle programming
import turtle

t = turtle.Turtle()
t.fillcolor('orange')
t.begin_fill()
for i in range(5):
  t.forward(150)
  t.right(144)
t.end_fill()

上述程序的输出

Python Turtle 中的彩色填充星星

在 Python Turtle 中绘制颜色填充的六边形

#Python program to draw color filled hexagon in turtle programming
import turtle

t = turtle.Turtle()
t.fillcolor('orange')
t.begin_fill()
for i in range(6):
  t.forward(150)
  t.right(60)
t.end_fill()

上述程序的输出

Python Turtle 中的颜色填充六边形

在 Python Turtle 中绘制彩色填充圆圈

#Python program to draw color filled circle in turtle programming
import turtle

t = turtle.Turtle()
t.fillcolor('orange')
t.begin_fill()
t.circle(100)
t.end_fill()

上述程序的输出

Python Turtle 中的颜色填充圆圈

 


版权声明:本文为allway2原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。