自己的事情自己做:使用 Python Turtle 绘制 Python Logo

以下代码中,将向你展示一个有趣的程序,如何使用 Python Turtle 中绘制 Python Logo。Python 翻译成汉语是蟒蛇的意思,Python 的 Logo 也是两条缠绕在一起的蟒蛇。
在这里插入图片描述

import turtle

pen = turtle.Turtle()
turtle.bgcolor("black")
pen.speed(10)
pen.pensize(2)
pen.pencolor("white")

def s_curve():
    for i in range(90):
        pen.left(1)
        pen.forward(1)

def r_curve():
    for i in range(90):
        pen.right(1)
        pen.forward(1)

def l_curve():
    s_curve()
    pen.forward(80)
    s_curve()

def l_curve1():
    s_curve()
    pen.forward(90)
    s_curve()

def half():
    pen.forward(50)
    s_curve()
    pen.forward(90)
    l_curve()
    pen.forward(40)
    pen.left(90)
    pen.forward(80)
    pen.right(90)
    pen.forward(10)
    pen.right(90)
    pen.forward(120)
    l_curve1()
    pen.forward(30)
    pen.left(90)
    pen.forward(50)
    r_curve()
    pen.forward(40)
    pen.end_fill()
def get_pos():
    pen.penup()
    pen.forward(20)
    pen.right(90)
    pen.forward(10)
    pen.right(90)
    pen.pendown()

def eye():
    pen.penup()
    pen.right(90)
    pen.forward(160)
    pen.left(90)
    pen.forward(70)
    pen.pencolor("black")
    pen.dot(35)

def sec_dot():
    pen.left(90)
    pen.penup()
    pen.forward(310)
    pen.left(90)
    pen.forward(120)
    pen.pendown()
    pen.dot(35)

pen.fillcolor("#306998")
pen.begin_fill()
half()
pen.end_fill()
get_pos()
pen.fillcolor("#FFD43B")
pen.begin_fill()
half()
pen.end_fill()
eye()
sec_dot()
pen.hideturtle()
turtle.done()
上一篇:Python进阶编程 --- 3.闭包、装饰器、设计模式、多线程、网络编程、正则表达式、递归


下一篇:简单3步制作纸质英语绘本的mp3英语朗读音频