[python]代码库
import turtle
import time
turtle.setup(800, 600)
t = turtle.Pen()
t.shape('turtle')
t.color('red')
t.pensize(5)
t.speed(0)
t.up()
t.backward(300)
t.down()
def drawgap():
t.up()
t.fd(5)
def drawline(flag):
drawgap()
if flag:
t.down()
else:
t.up()
t.fd(40)
drawgap()
t.right(90)
def drawdigit(num):
drawline(True) if num in [2, 3, 4, 5, 6, 8, 9] else drawline(False)
drawline(True) if num in [0, 1, 3, 4, 5, 6, 7, 8, 9] else drawline(False)
drawline(True) if num in [0, 2, 3, 5, 6, 8, 9] else drawline(False)
drawline(True) if num in [0, 2, 6, 8] else drawline(False)
t.left(90)
drawline(True) if num in [0, 4, 5, 6, 8, 9] else drawline(False)
drawline(True) if num in [0, 2, 3, 5, 6, 7, 8, 9] else drawline(False)
drawline(True) if num in [0, 1, 2, 3, 4, 6, 8, 9] else drawline(False)
t.up()
t.left(180)
t.forward(20)
def drawdate(date):
t.color('red')
for i in date:
if i == "-":
t.write('年', font=("Arial", 25, "normal"))
t.color('blue')
t.fd(40)
elif i == "/":
t.write('月', font=("Arial", 25, "normal"))
t.color('black')
t.fd(40)
elif i == "+":
t.write('日', font=("Arial", 25, "normal"))
else:
drawdigit(eval(i))
def programmer():
t.up()
t.goto(-150, 100)
t.down()
t.color('black')
t.write('2022程序员节快乐', font=("Arial", 32, "normal"))
t.up()
t.goto(0, 0)
t.down()
programmer()
def main():
t.color('red')
t.pensize(5)
t.speed(0)
t.up()
t.backward(300)
t.down()
drawdate(time.strftime("%Y-%m/%d+", time.localtime()))
t.hideturtle()
main()
turtle.done()
# 实现完成
[代码运行效果截图]