如何用python的turtle库画scp的logo

去年暑假接触了scp,当时用python画了一个logo。本来代码很乱,今天重构了一下。

代码:

import turtle as t

###############################################################################
# 初始化

bgcolor = 'black' # 背景颜色
pencolor = 'white' # 笔颜色
fill_color = 'grey' # 填充颜色

t.speed(0) # 绘图速度
t.pensize(6) # 笔直径
t.bgcolor(bgcolor) # 设置背景颜色
t.pencolor(pencolor) # 设置画笔颜色
t.fillcolor(fill_color) # 设置填充颜色

###############################################################################

def go(xy):
    t.penup()
    t.goto(xy)
    t.pendown()

def circle_frame():
    # 画圆边框
    t.fillcolor(fill_color)
    t.begin_fill()
    go((0, -200))
    t.circle(200, 40)
    t.pencolor(bgcolor)
    for x in range(3):
        t.circle(200, 40)
        t.pencolor(pencolor)
        t.circle(200, 80)
        t.pencolor(bgcolor)
    t.pencolor(pencolor)
    t.end_fill()

def straight_frame(seth1, seth2, seth3, seth4):
    # 画直边框
    t.begin_fill()
    t.seth(seth1)
    t.fd(3)
    pos1 = t.pos()
    t.fd(57)
    pos2 = t.pos()
    t.bk(60)
    pos3 = t.pos()
    t.pencolor(fill_color)
    t.seth(seth2)
    t.circle(200, 40)
    t.pencolor(pencolor)
    pos4 = t.pos()
    t.seth(seth3)
    t.fd(60)
    t.goto(pos2)
    t.end_fill()

    if seth4 != False:
        go(pos4)
        t.seth(seth4)
        t.circle(200, 80)
    else:
        go((0, -140))
        t.seth(0)

    return (pos1, pos2, pos3, pos4)

def draw_circle():
    t.pensize(18)
    t.circle(140, 420)
    t.seth(150)
    t.pensize(12)

def draw_arrow(seth1, seth3, cir=False):
    if seth1 != False:
        go((0, -140))
        t.seth(0)
        t.circle(140, cir)
        t.pensize(12)
        t.seth(seth1)
    else:
        pass

    t.bk(30)
    t.fd(150)
    t.pensize(1)
    t.fd(12)
    t.begin_fill()
    t.seth(seth3)
    t.fd(60)
    f = t.pos()
    t.bk(60)
    t.right(50)
    t.fd(60)
    t.goto(f)
    t.end_fill()

def clear_dot():
    go(a1)
    t.dot(6)
    go(a2)
    t.dot(6)
    go(b1)
    t.dot(6)
    go(b2)
    t.dot(6)
    go(c1)
    t.dot(6)
    go(c2)
    t.dot(6)

###############################################################################

if __name__ == '__main__':
    # 画圆边框
    circle_frame()
    # 画直边框
    a2, a, a1, b = straight_frame(335, 40, 325, 80)
    b2, c, b1, d = straight_frame(95, 160, 85, 200)
    c2, e, c1, z = straight_frame(215, 280, 205, False)
    # 画箭头时要用
    t.fillcolor(pencolor)
    # 画一个圆
    draw_circle()
    # 画三个箭头
    draw_arrow(False, 355)
    draw_arrow(270, 115, 180)
    draw_arrow(30, 235, -60)
    # 清除多余的点
    clear_dot()
    # 隐藏海龟
    t.hideturtle()
    # 让画面不消失
    t.done()

效果图

在这里插入图片描述

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值