VOL 300
21
2021-09
今天距2022年102天
这是ITester软件测试小栈第300次推文
点击上方蓝字“ITester软件测试小栈“关注我,每周一、三、五早上 09:00准时推送,每月不定期赠送技术书籍。
微信公众号后台回复“资源”、“测试工具包”领取测试资源,回复“微信交流群”、“内推群”一起进群打怪。
本文3102字,阅读约需8分钟
Hi,大家好。中秋和国庆,都是让人期待的节日。在此祝大家节日快乐,技能飙升,天天开心。每逢佳节,总想要换个发型、头像之类以应景。今天我们使用 Python 来给自己的头像加一个小国旗或小月饼,几行代码就能搞定,如果想要获取本文完整代码可在ITester软件测试小栈微信公众号后台回复“头像源码
”。
一
月饼头像制作
我们可以使用 Python 来画一个月饼🥮,用到的 Python 库是 turtle
,月饼组成元素主要包括:外层圆形的花纹轮廓、内层馅和文字。
1
绘制外层花纹轮廓
#!/usr/bin/python3
# -*- coding:utf-8 -*-
# @File:flag.py
# @Software:PyCharm
# @微信公众号:ITester软件测试小栈
# @Author:coco
import turtle
turtle.speed(100)
turtle.color("#F5E16F")
for i in range(20):
# 顺时针移动18度
turtle.right(18)
turtle.begin_fill()
# 向前移动的距离
turtle.forward(220)
# 画半径为 40 的半圆
turtle.circle(40, 180)
# 画完半圆之后回到(0,0)
turtle.goto(0, 0)
turtle.right(360)
turtle.end_fill()
实现效果如下:
2
绘制月饼馅
实现效果如下:
最后添加文字,比如豆沙、莲蓉、流心、冰皮,绘制流心月饼代码实现如下:
#!/usr/bin/python3
# -*- coding:utf-8 -*-
# @File:moon_cake.py
# @微信公众号:ITester软件测试小栈
turtle.color("#F5E16F")
turtle.write("流心", font=("隶书", 60, "bold"))
效果如下:
3
头像加月饼
pip install opencv-python
pip install -i https://mirrors.aliyun.com/pypi/simple/ opencv-python
准备头像如下:
头像加月饼这个功能实现起只需十几行 Python 代码就可以搞定,代码如下:
头像加个小月饼,效果如下:
二
国旗头像制作
我们可以使用 Python 来画一面国旗,用到的 Python 库同样是 turtle
,五星红旗组成元素包括:红底旗、一颗黄色主星和四颗黄色副星。
1
绘制红底旗
#!/usr/bin/python3
# -*- coding:utf-8 -*-
# @File:flag.py
# @Software:PyCharm
# @微信公众号:ITester软件测试小栈
# @Author:coco
import turtle
turtle.setup(600, 400, 0, 0)
turtle.bgcolor("red")
实现效果如下:
2
绘制五角星
首先画一颗主星,代码如下:
实现效果如下:
接下来画四颗副星,代码实现如下:
# 副星1
turtle.begin_fill()
turtle.up()
turtle.goto(-100,180)
turtle.setheading(305)
turtle.down()
for i in range (5):
turtle.forward(50)
turtle.left(144)
turtle.end_fill()
# 副星2
turtle.begin_fill()
turtle.up()
turtle.goto(-50,110)
turtle.setheading(30)
turtle.down()
for i in range (5):
turtle.forward(50)
turtle.right(144)
turtle.end_fill()
# 副星3
turtle.begin_fill()
turtle.up()
turtle.goto(-40,50)
turtle.setheading(5)
turtle.down()
for i in range (5):
turtle.forward(50)
turtle.right(144)
turtle.end_fill()
# 副星4
turtle.begin_fill()
turtle.up()
turtle.goto(-100,10)
turtle.setheading(300)
turtle.down()
for i in range (5):
turtle.forward(50)
turtle.left(144)
turtle.end_fill()
实现效果如下:
3
头像加国旗
pip install opencv-python
pip install -i https://mirrors.aliyun.com/pypi/simple/ opencv-python
准备头像如下:
头像加国旗这个功能实现起来也比较简单,只需十几行 Python 代码就可以搞定,代码实现如下:
头像加个小国旗,效果如下:
今日份月饼或国旗头像安排上了吗?如果想要获取本文完整代码可在ITester软件测试小栈微信公众号后台回复“头像源码
”,代码结构如下所示:
今天是中秋节,祝各位小伙伴中秋快乐,快试试用Python制作自己喜欢口味的月饼吧~
以上
That‘s all
更多系列文章
敬请期待
ITester软件测试小栈(ID:ITestingA),专注于软件测试技术和宝藏干货分享,每周准时更新原创技术文章,每月不定期赠送技术书籍,愿我们在更高处相逢。喜欢记得星标⭐我,每周及时获得最新推送,第三方转载请注明出处。
ITester软件测试小栈
本文分享自 ITester软件测试小栈 微信公众号,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。
本文参与 腾讯云自媒体同步曝光计划 ,欢迎热爱写作的你一起参与!