Python源码17:使用海龟画图turtle画五星红旗

turtle模块是一个Python的标准库之一,它提供了一个基于Turtle graphics的绘图库。Turtle graphics是一种流行的绘图方式,它通过控制一个小海龟在屏幕上移动来绘制图形。

turtle模块可以让您轻松地创建和控制海龟图形,从而帮助您学习Python编程和图形编程的基本概念。您可以使用turtle模块绘制各种形状、线条和图案,还可以通过添加颜色和其他效果来增强绘图的视觉效果。

turtle模块还提供了一些简单的函数和命令,例如前进、后退、转向、设置画笔颜色和粗细等等。这些函数和命令使得您可以轻松地控制海龟的移动和绘图行为。此外,turtle模块还提供了一些高级功能,例如创建自己的绘图函数、保存和加载绘图文件等等。

总之,turtle模块是一个非常适合初学者使用的Python库,它可以帮助您学习Python编程和图形编程的基本概念,并为您提供了一个轻松愉快的绘图环境。
在这里插入图片描述


#五星红旗
import turtle as t

t.speed(10)
t.hideturtle()  #隐藏图标

t.pencolor("red")

#外框
t.penup()
t.goto(-300, 200)
t.pendown()
t.begin_fill()
t.fillcolor("red")
t.fd(600)
t.right(90)
t.fd(400)
t.right(90)
t.fd(600)
t.right(90)
t.fd(400)
t.right(90)
t.end_fill()

t.pencolor("yellow")

#大星星
t.penup()
t.goto(-275, 115)
t.pendown()
t.begin_fill()
t.fillcolor("yellow")
t.forward(90)
t.right(144)
t.forward(90)
t.right(144)
t.forward(90)
t.right(144)
t.forward(90)
t.right(144)
t.forward(90)
t.end_fill()

#小星星1
t.seth(0)
t.left(25)
t.penup()
t.goto(-187, 169)
t.pendown()


t.begin_fill()
t.fillcolor("yellow")
t.forward(30)
t.right(144)
t.forward(30)
t.right(144)
t.forward(30)
t.right(144)
t.forward(30)
t.right(144)
t.forward(30)
t.end_fill()

#小星星2
t.penup()
t.goto(-275, 115)
t.pendown()
t.seth(0)
t.left(21)
t.penup()
t.goto(-147, 133)
t.pendown()

t.begin_fill()
t.fillcolor("yellow")
t.forward(30)
t.right(144)
t.forward(30)
t.right(144)
t.forward(30)
t.right(144)
t.forward(30)
t.right(144)
t.forward(30)
t.end_fill()

#小星星3
t.penup()
t.goto(-275, 115)
t.pendown()
t.seth(0)
t.right(21)
t.penup()
t.goto(-147, 93)
t.pendown()


t.begin_fill()
t.fillcolor("yellow")
t.forward(30)
t.right(144)
t.forward(30)
t.right(144)
t.forward(30)
t.right(144)
t.forward(30)
t.right(144)
t.forward(30)
t.end_fill()

#小星星4
t.penup()
t.goto(-275, 115)
t.pendown()
t.seth(0)
t.right(25)
t.penup()
t.goto(-187, 41)
t.pendown()


t.begin_fill()
t.fillcolor("yellow")
t.forward(30)
t.right(144)
t.forward(30)
t.right(144)
t.forward(30)
t.right(144)
t.forward(30)
t.right(144)
t.forward(30)
t.end_fill()
t.done()

完毕!!感谢您的收看

----------★★历史博文集合★★----------

我的零基础Python教程,Python入门篇 进阶篇 视频教程 Py安装py项目 Python模块 Python爬虫 Json Xpath 正则表达式 Selenium Etree CssGui程序开发 Tkinter Pyqt5 列表元组字典数据可视化 matplotlib 词云图 Pyecharts 海龟画图 Pandas Bug处理 电脑小知识office自动化办公 编程工具

猜你喜欢

转载自blog.csdn.net/gxz888/article/details/134828029
今日推荐