zoukankan      html  css  js  c++  java
  • 7段数码管绘制

    import turtle as t
    import time
    def popspace(): #单管间隔
        t.penup()
        t.fd(4)
    def popline(draw):   #画数码管
        popspace()
        t.pendown() if draw else t.penup()
        t.fd(40)
        popspace()
        t.right(90)
    def popstart(d): #画数字数码管
        popline(True) if d in [2,3,4,5,6,8,9] else popline(False)
        popline(True) if d in [0,1,3,4,5,6,7,8,9] else popline(False)
        popline(True) if d in [0,2,3,5,6,8,9] else popline(False)
        popline(True) if d in [0,2,6,8] else popline(False)
        t.left(90)
        popline(True) if d in [0,4,5,6,8,9] else popline(False)
        popline(True) if d in [0,2,3,5,6,7,8,9] else popline(False)
        popline(True) if d in [0,1,2,3,4,7,8,9] else popline(False)
        t.left(180)
        t.penup()
        t.fd(30)
    def popdate(date):
        t.pencolor("red")
        for i in date:
            if i == '*':
                t.write('',font=("宋体", 30, "normal"))
                t.pencolor(("black"))
                t.fd(60)
            elif i == '/':
                t.write('',font=("宋体", 30, "normal"))
                t.pencolor("orange")
                t.fd(60)
            elif i == '!':
                t.write('',font=("宋体", 30, "normal"))
            else:
                popstart(eval(i))
    def main():
        t.setup(800, 700, 200,200)
        t.penup()
        t.fd(-350)
        t.pensize(4)
        popdate(time.strftime('%H*%M/%S!',time.localtime()))
        t.hideturtle()
    main()

    import turtle,datetime
    def drawLine(draw):
        turtle.pendown() if draw else turtle.penup()
        turtle.fd(40)
        turtle.right(90)
    def drawDigit(d):
        drawLine(True) if d in [2, 3, 4, 5, 6, 8, 9] else drawLine(False)
        drawLine(True) if d in [0, 1, 3, 4, 5, 6, 7, 8, 9] else drawLine(False)
        drawLine(True) if d in [0, 2, 3, 5, 6, 8, 9] else drawLine(False)
        drawLine(True) if d in [0, 2, 6, 8] else drawLine(False)
        turtle.left(90)
        drawLine(True) if d in [0, 4, 5, 6, 8, 9] else drawLine(False)
        drawLine(True) if d in [0, 2, 3, 5, 6, 7, 8, 9] else drawLine(False)
        drawLine(True) if d in [0, 1, 2, 3, 4, 7, 8, 9] else drawLine(False)
        turtle.left(180)
        turtle.penup()
        turtle.fd(20)
    def drawDate(date):
        for i in date:
            drawDigit(eval(i))
    def main():
        turtle.setup(800, 350, 200, 200)
        turtle.penup()
        turtle.fd(-300)
        turtle.pensize(5)
        drawDate(datetime.datetime.now().strftime('%w'))
        print("
    ")
        
        turtle.hideturtle()
    main()

  • 相关阅读:
    WSGI原理
    主从数据库
    mysql高级
    记录
    获取当前时间
    sql注入和防sql注入
    python操作MySQL
    修改Windows10 命令终端cmd的编码为UTF-8
    MySQL查询
    MySQL数据库操作
  • 原文地址:https://www.cnblogs.com/20200508zp/p/13837479.html
Copyright © 2011-2022 走看看