• 用 Python 画一个捂脸表情



    微信中的捂脸表情相信大家都不陌生,我见过以及自己使用这个表情的频率都是比较高的,可以说这个表情算是大部分人的主打表情之一了,本文我使用 Python 来画一下这个表情,我们使用到的库还是 turtle。

    实现

    因微信中的表情较小,我到网上找了一个大一点的,一起来看一下:

    从图中我们可以看出这个表情由:脸框(那个大圆圈)、手、眼睛、眼泪、嘴(包括牙齿),下面我们看一下如何使用 Python 来画它。

    首先,我们来画脸框,代码实现如下:

    turtle.speed(5)
    turtle.setup(500, 500)
    turtle.pensize(5)
    turtle.right(90)
    turtle.penup()
    turtle.fd(100)
    turtle.left(90)
    turtle.pendown()
    turtle.begin_fill()
    turtle.pencolor("#B8860B")
    turtle.circle(150)
    turtle.fillcolor("#FFFF99")
    turtle.end_fill()
    

    看一下效果:

    接着来画嘴(包括牙齿),代码实现如下:

    turtle.penup()
    turtle.goto(77, 20)
    turtle.pencolor("#B8860B")
    turtle.goto(0, 50)
    turtle.right(30)
    turtle.fd(110)
    turtle.right(90)
    turtle.pendown()
    turtle.begin_fill()
    turtle.fillcolor("#925902")
    turtle.circle(-97, 160)
    turtle.goto(92, -3)
    turtle.end_fill()
    turtle.penup()
    turtle.goto(77, -25)
    # 牙齿
    turtle.pencolor("white")
    turtle.begin_fill()
    turtle.fillcolor("white")
    turtle.goto(77, -24)
    turtle.goto(-81, 29)
    turtle.goto(-70, 43)
    turtle.goto(77, -8)
    turtle.end_fill()
    turtle.penup()
    turtle.goto(0, -100)
    turtle.setheading(0)
    turtle.pendown()
    

    看一下效果:

    再接着来画眼泪,代码实现如下:

    # 左边眼泪
    turtle.left(90)
    turtle.pensize(3)
    turtle.penup()
    turtle.fd(150)
    turtle.right(60)
    turtle.fd(-150)
    turtle.pendown()
    turtle.left(20)
    turtle.pencolor("#155F84")
    turtle.fd(150)
    turtle.right(180)
    position1 = turtle.position()
    turtle.begin_fill()
    turtle.fillcolor("#B0E0E6")
    turtle.fd(150)
    turtle.right(20)
    turtle.left(270)
    turtle.circle(-150, 18)
    turtle.right(52)
    turtle.fd(110)
    position2 = turtle.position()
    turtle.goto(-33, 90)
    turtle.end_fill()
    # 右边眼泪
    turtle.penup()
    turtle.goto(0, 0)
    turtle.setheading(0)
    turtle.left(90)
    turtle.fd(50)
    turtle.right(150)
    turtle.fd(150)
    turtle.left(150)
    turtle.fd(100)
    turtle.pendown()
    turtle.begin_fill()
    turtle.fd(-100)
    turtle.fillcolor("#B0E0E6")
    turtle.right(60)
    turtle.circle(150, 15)
    turtle.left(45)
    turtle.fd(66)
    turtle.goto(77, 20)
    turtle.end_fill()
    

    看一下效果:

    再接着画眼睛,代码实现如下:

    turtle.pensize(5)
    turtle.penup()
    turtle.pencolor("black")
    turtle.goto(-65, 75)
    turtle.setheading(0)
    turtle.left(27)
    turtle.fd(30)
    turtle.pendown()
    turtle.begin_fill()
    turtle.fillcolor("black")
    turtle.left(90)
    turtle.circle(30, 86)
    turtle.goto(position2[0], position2[1])
    turtle.goto(position1[0], position1[1])
    turtle.end_fill()
    

    看一下效果:

    最后,我们来画手,代码实现如下:

    turtle.pencolor("#B8860B")
    turtle.fillcolor("#FFFF99")
    arc(-110, 10, 110, -40, 30)
    turtle.begin_fill()
    turtle.circle(300, 35)
    turtle.circle(13, 120)
    turtle.setheading(-50)
    turtle.fd(20)
    turtle.setheading(130)
    turtle.circle(200, 15)
    turtle.circle(12, 180)
    turtle.fd(40)
    turtle.setheading(137)
    turtle.circle(200, 16)
    turtle.circle(12, 160)
    turtle.setheading(-35)
    turtle.fd(45)
    turtle.setheading(140)
    turtle.circle(200, 13)
    turtle.circle(11, 160)
    turtle.setheading(-35)
    turtle.fd(40)
    turtle.setheading(145)
    turtle.circle(200, 9)
    turtle.circle(10, 180)
    turtle.setheading(-31)
    turtle.fd(50)
    turtle.setheading(-45)
    turtle.pensize(7)
    turtle.right(5)
    turtle.circle(180, 35)
    turtle.end_fill()
    turtle.begin_fill()
    turtle.setheading(-77)
    turtle.fd(50)
    turtle.left(-279)
    turtle.fd(16)
    turtle.circle(29, 90)
    turtle.end_fill()
    

    看一下最终效果:

    是不是有内味了。

    总结

    本文我们使用 Python 画了一个捂脸表情,如果大家对实现效果不满意的话,可以自己动手将它修改成自己满意的样子。


    本公众号全部原创已整理成一个专栏,请在公众号里回复「测试开发」获取!
    推荐阅读:
    App自动化测试方案。
    
    浅谈如何自动化生成测试脚本...
    
    有没有好到简历模版可以参考一下
    
    测试开发技术资源大放送!包括但不限于:测试理论,测试开发,Python,Java,自动化测试,人工智能测试,测试管理,测试工具,性能测试,接口测试,安全测试,app专项测试,招聘内推,求职,selenium,appium,jmeter,linux,mysql,测试课程,等等。在下面公众号内回复「1024」,即可免费获取!!
    
    

  • 相关阅读:
    NLP(二十一)根据已有文本LSTM自动生成文本
    Keras(五)LSTM 长短期记忆模型 原理及实例
    Keras(六)Autoencoder 自编码 原理及实例 Save&reload 模型的保存和提取
    NLP(二十) 利用词向量实现高维词在二维空间的可视化
    Keras(四)CNN 卷积神经网络 RNN 循环神经网络 原理及实例
    NLP(十六) DL在NLP中的应用
    Keras(三)backend 兼容 Regressor 回归 Classifier 分类 原理及实例
    ValueError: Error when checking input: expected conv2d_1_input to have 4 dimensions, but got array with shape (60000, 28, 28)
    Keras(二)Application中五款已训练模型、VGG16框架解读
    Python实现 下载IJCAI会议所有论文
  • 原文地址:https://www.cnblogs.com/finer/p/14127737.html
Copyright © 2020-2023  润新知