用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()

测试效果:
在这里插入图片描述

  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Franda914

有钱的捧个钱场,没钱的点的赞

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值