用turtle库绘制Python Logo图案

import turtle
import math
#PythonLogo.
lenth = 50# 三角短边长度
WIDETH = math.sqrt(2) * lenth# 三角长边长度
'''横向前四节蛇身'''
def draw_crossbody1():
    for i in range(4):
        turtle.fillcolor("blue")
        turtle.begin_fill()
        turtle.left(45)
        turtle.fd(lenth)# 1
        turtle.right(90)
        turtle.fd(lenth)# 2
        turtle.right(135)
        turtle.fd(WIDETH)# 3
        turtle.right(135)
        turtle.fd(lenth)# 4
        turtle.right(45)
        turtle.fd(WIDETH)# 5
        turtle.right(135)
        turtle.fd(lenth)# 6
        turtle.right(-135)
        turtle.end_fill()

'''横向最后半节蛇身'''
def draw_crossbody2():
    turtle.fillcolor("blue")
    turtle.begin_fill()
    turtle.left(45)
    turtle.fd(lenth)# 1
    turtle.right(90)
    turtle.fd(lenth)# 2
    turtle.right(135)
    turtle.fd(WIDETH)# 3
    turtle.right(135)
    turtle.fd(lenth)# 4
    turtle.right(90)
    turtle.fd(lenth)# 5
    turtle.right(-135)
    turtle.end_fill()

'''纵向一节蛇身'''
def draw_lenbody1():
    turtle.fillcolor("blue")
    turtle.begin_fill()
    turtle.left(45)
    turtle.fd(lenth)  # 1
    turtle.right(90)
    turtle.fd(lenth)  # 2
    turtle.right(135)
    turtle.fd(WIDETH)  # 3
    turtle.right(135)
    turtle.fd(lenth)  # 4
    turtle.right(45)
    turtle.fd(WIDETH)  # 5
    turtle.right(135)
    turtle.fd(lenth)  # 6
    turtle.right(-135)
    turtle.end_fill()

'''纵向最后半节蛇身'''
def draw_lenbody2():
    turtle.fillcolor("blue")
    turtle.begin_fill()
    turtle.left(45)
    turtle.fd(lenth)# 1
    turtle.right(90)
    turtle.fd(lenth)# 2
    turtle.right(135)
    turtle.fd(WIDETH)# 3
    turtle.right(135)
    turtle.fd(lenth)# 4
    turtle.right(90)
    turtle.fd(lenth)# 5
    turtle.right(-135)
    turtle.end_fill()

'''蛇头'''
def draw_head():
    turtle.fillcolor("blue")
    turtle.begin_fill()
    turtle.fd(WIDETH)# 7
    turtle.left(135)
    turtle.fd(lenth)# 8
    turtle.end_fill()


'''蛇眼'''
def draw_eye():
    turtle.penup()
    turtle.goto(4.5*WIDETH-200,2*WIDETH-0.5*lenth/30)
    turtle.pendown()
    turtle.left(45)
    turtle.circle(-6.5*lenth/30)

    turtle.penup()
    turtle.goto(4.5*WIDETH-200,2*WIDETH-4.5*lenth/30)
    turtle.pendown()
    turtle.circle(-3*lenth/30)

'''书写logo标题'''
def draw_write():
    turtle.penup()
    turtle.goto(-75,-240)
    turtle.pencolor('brown')
    turtle.write("Python\n\n", align="center", font=("楷体",96, "bold"))

'''绘画python logo'''
def draw_logo():
    turtle.pu()
    turtle.goto(-200,0)
    turtle.pd()
    turtle.hideturtle()
    turtle.pensize(2)
    turtle.pencolor("white")
    draw_crossbody1()
    draw_crossbody2()
    draw_lenbody1()
    draw_lenbody2()
    draw_head()
    draw_eye()
    draw_write()

turtle.tracer(0)
draw_logo()
turtle.done()

测试效果:
用turtle库绘制Python Logo图案_第1张图片

你可能感兴趣的:(python学习日记,python)