在Python中使用Turtle绘制笑脸表情符号 |
您所在的位置:网站首页 › python画图怎么画半圆 › 在Python中使用Turtle绘制笑脸表情符号 |
在Python中使用Turtle绘制笑脸表情符号
Turtle 是Python中的一个内置模块。它提供了使用屏幕(纸板)和Turtle(笔)的绘画。为了在屏幕上画东西,我们需要移动Turtle。为了移动Turtle,有一些函数,即forward(), backward() 等等。 在这篇文章中,我们将看到如何使用_Turtle _模块绘制一个笑脸表情符号。 1.绘制笑脸。 以下是使用的步骤。 import Turtle。 制作物品。 画一个圆,填上黄色。 用两个圆圈画出眼睛,分别填充白色和黑色。 画出鼻子的圆圈并填充黑色。 画半圆作为嘴。 画出舌头的半圆,并填充红色。以下是执行情况。 # 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()输出 : 2.让我们画一个不同的微笑表情符号,上面所画的只是为了更好地理解它。 以下是使用的步骤。 import turtle。 定义笔的大小和笔的宽度。 绘制一个圆圈。 用两个圆圈画出眼睛,并分别填充红色。 画出鼻子的三角形. 绘制嘴巴的半圆。以下是相同的实现方式:- #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 () |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |