用 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 畫了一個捂臉表情,如果大家對實現效果不滿意的話,可以自己動手將它修改成自己滿意的樣子。

獲取源碼,後臺回覆:【捂臉】

往期熱門:

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章