去年暑假接触了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()