基于Python的turtle库绘制党旗的基本介绍


前言

本文主要简略介绍利用Python的turtle库绘制党旗的过程,内容全为作者自己设计,存在不足之处望读者多多包涵。


基本流程

1.引入库

代码如下(示例):

import turtle as t

2.绘制背景

利用turtle绘制出相应尺寸的矩形,然后对其进行填充。
代码如下(示例):

t.color("red")
t.penup()
t.goto(-300, 200)
t.pendown()
t.begin_fill()
t.forward(600)
t.right(90)
t.forward(400)
t.right(90)
t.forward(600)
t.right(90)
t.forward(400)
t.end_fill()

3.绘制镰刀与斧头图案

代码如下(实例):

t.color("yellow")
t.penup()
t.goto(-220, 100)
t.pendown()

t.begin_fill()
t.right(45)
t.forward(50)
t.right(60)
t.circle(50, 15)
t.right(45)
t.forward(13)
t.right(90)
t.forward(18)
t.left(90)
t.forward(100)
t.right(90)
t.forward(22)
t.right(90)
t.forward(100)
t.left(90)
t.forward(18)
t.right(90)
t.forward(22)

t.end_fill()


t.penup()

t.goto(-148, 156)
t.right(180)
t.pendown()

t.begin_fill()
t.circle(-85, 35)
t.circle(-60, 150)
t.left(90)
t.forward(22)
t.left(90)
t.circle(83, 86)
t.circle(71, 121)
t.penup()
t.end_fill()

t.goto(-216, 28)
t.right(15)
t.pendown()
t.begin_fill()
t.circle(10)
t.end_fill()

完整程序展示如下:

# 绘制党旗,党旗尺寸为120cmx80cm,此处等比例放大5倍
# 导入第三方库
import turtle as t

# 绘制党旗红色背景
# 设置画笔颜色为红色,后期填充也是红色
t.color("red")
# 抬起画笔
t.penup()
# 选择起始点
t.goto(-300, 200)
# 放下画笔用于绘图
t.pendown()
# 开始绘画填充
t.begin_fill()
t.forward(600)
t.right(90)
t.forward(400)
t.right(90)
t.forward(600)
t.right(90)
t.forward(400)
t.end_fill()

# 绘制镰刀和斧头
# 设置画笔颜色为黄色
# 绘制斧头
t.color("yellow")
t.penup()
t.goto(-220, 100)
t.pendown()
# 开始填充
t.begin_fill()
t.right(45)
t.forward(50)
t.right(60)
t.circle(50, 15)
t.right(45)
t.forward(13)
t.right(90)
t.forward(18)
t.left(90)
t.forward(100)
t.right(90)
t.forward(22)
t.right(90)
t.forward(100)
t.left(90)
t.forward(18)
t.right(90)
t.forward(22)
# 完成填充
t.end_fill()

# 开始绘制镰刀
t.penup()
# 确定镰刀绘制开始点
t.goto(-148, 156)
t.right(180)
t.pendown()
# 开始绘制镰刀并填充
t.begin_fill()
t.circle(-85, 35)
t.circle(-60, 150)
t.left(90)
t.forward(22)
t.left(90)
t.circle(83, 86)
t.circle(71, 121)
t.penup()
t.end_fill()

# 完善镰刀细节
t.goto(-216, 28)
t.right(15)
t.pendown()
t.begin_fill()
t.circle(10)
t.end_fill()

# 防止最后绘图窗口一闪而过
turtle.done()

运行效果如下:

Alt


总结

本文简要介绍了基于Python的turtle库绘制党旗的方法,具体的细节还需要不断的完善,望读者见谅。

  • 10
    点赞
  • 32
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值