📜  在Python中使用 Turtle 绘制笑脸表情符号

📅  最后修改于: 2022-05-13 01:54:22.994000             🧑  作者: Mango

在Python中使用 Turtle 绘制笑脸表情符号

先决条件: Python Turtle 基础

Turtle是Python中的一个内置模块。它使用屏幕(纸板)和海龟(笔)提供绘图。要在屏幕上绘制一些东西,我们需要移动海龟。要移动海龟,有一些函数,即forward()、backward()等。

在本文中,我们将了解如何使用Turtle模块绘制笑脸表情符号

1.)画笑脸:

下面是实现:

Python3
# Python program to draw smile
# face emoji using turtle
import turtle
 
# turtle object
pen = turtle.Turtle()
 
# function for creation of eye
def eye(col, rad):
    pen.down()
    pen.fillcolor(col)
    pen.begin_fill()
    pen.circle(rad)
    pen.end_fill()
    pen.up()
 
 
# draw face
pen.fillcolor('yellow')
pen.begin_fill()
pen.circle(100)
pen.end_fill()
pen.up()
 
# draw eyes
pen.goto(-40, 120)
eye('white', 15)
pen.goto(-37, 125)
eye('black', 5)
pen.goto(40, 120)
eye('white', 15)
pen.goto(40, 125)
eye('black', 5)
 
# draw nose
pen.goto(0, 75)
eye('black', 8)
 
# draw mouth
pen.goto(-40, 85)
pen.down()
pen.right(90)
pen.circle(40, 180)
pen.up()
 
# draw tongue
pen.goto(-10, 45)
pen.down()
pen.right(180)
pen.fillcolor('red')
pen.begin_fill()
pen.circle(10, 180)
pen.end_fill()
pen.hideturtle()


Python3
#import module
import turtle
 
#define pen size
turtle.pensize (5)
 
#define pen color
turtle.pencolor ("Blue")
 
#for outer bigger circle
turtle.fillcolor ("red")
turtle.penup ()
turtle.goto (0, -200)
turtle.pendown ()
turtle.circle (200)
 
#for eyes
turtle.penup ()
turtle.goto (-100,50)
turtle.pendown ()
turtle.begin_fill ()
turtle.circle (17.5)
turtle.end_fill ()
turtle.penup ()
turtle.goto (100,50)
turtle.pendown ()
turtle.begin_fill ()
turtle.circle (17.5)
turtle.end_fill ()
 
#for nose
turtle.penup ()
turtle.goto (0,50)
turtle.pendown ()
turtle.circle (-70, steps=3)
 
# for smile
turtle.penup ()
turtle.goto (-100, -70)
turtle.pendown ()
turtle.right (90)
turtle.circle (100,180)
turtle.mainloop ()


输出 :

微笑的面孔

2. 让我们在上面画一个不同的微笑表情符号,以便更好地理解它。

以下是相同的实现:-

Python3

#import module
import turtle
 
#define pen size
turtle.pensize (5)
 
#define pen color
turtle.pencolor ("Blue")
 
#for outer bigger circle
turtle.fillcolor ("red")
turtle.penup ()
turtle.goto (0, -200)
turtle.pendown ()
turtle.circle (200)
 
#for eyes
turtle.penup ()
turtle.goto (-100,50)
turtle.pendown ()
turtle.begin_fill ()
turtle.circle (17.5)
turtle.end_fill ()
turtle.penup ()
turtle.goto (100,50)
turtle.pendown ()
turtle.begin_fill ()
turtle.circle (17.5)
turtle.end_fill ()
 
#for nose
turtle.penup ()
turtle.goto (0,50)
turtle.pendown ()
turtle.circle (-70, steps=3)
 
# for smile
turtle.penup ()
turtle.goto (-100, -70)
turtle.pendown ()
turtle.right (90)
turtle.circle (100,180)
turtle.mainloop ()

输出: