目录

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

在 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()

上述程序的输出

https://i-blog.csdnimg.cn/blog_migrate/b8a3c165382ce33c8eac287a67c4fe71.jpeg

在 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()

上述程序的输出

https://i-blog.csdnimg.cn/blog_migrate/4912e20f9c809c0d71dbf52758c924bf.jpeg

在 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()

上述程序的输出

https://i-blog.csdnimg.cn/blog_migrate/ffcc38f400f86d226bb4030d601504fc.jpeg

在 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()

上述程序的输出

https://i-blog.csdnimg.cn/blog_migrate/6db6d5af66e9e87f0079ba0d7e982b88.jpeg

在 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()

上述程序的输出

https://i-blog.csdnimg.cn/blog_migrate/bc9543aadc83177b9a5394d4da34a973.jpeg