• 7段数码管绘制


    import turtle, datetime
     
    def drawGap():         
        turtle.up()
        turtle.fd(5)
     
     
    def drawLine(draw):    
        drawGap()
        if(draw):
            turtle.down()
        else:
            turtle.up()
     
        turtle.fd(40)
        drawGap()
        turtle.right(90)
     
     
    def drawDigit(i):    
        if i in [2,3,4,5,6,8,9]:
            drawLine(True)
        else:
            drawLine(False)
     
        if i in [0,1,3,4,5,6,7,8,9]:
            drawLine(True)
        else:
            drawLine(False)
     
        if i in [0,2,3,5,6,8]:
            drawLine(True)
        else:
            drawLine(False)
     
        if i in [0,2,6,8]:
            drawLine(True)
        else:
            drawLine(False)
     
        turtle.left(90)
     
        if i in [0,4,5,6,8,9]:
            drawLine(True)
        else:
            drawLine(False)
     
        if i in [0,2,3,5,6,7,8,9]:
            drawLine(True)
        else:
            drawLine(False)
     
        if i in [0,1,2,3,4,7,8,9]:
            drawLine(True)
        else:
            drawLine(False)
     
        turtle.right(180)
        turtle.penup()
        turtle.fd(20)
     
     
     
    def drawData(time):
        turtle.pencolor("red")
        for i in time:
            if i == '-':
                turtle.write('年',font=("Arial", 18, "normal"))
                turtle.fd(38)
                turtle.pencolor("green")
            elif i == '+':
                turtle.write('月',font=("Arial", 18, "normal"))
                turtle.pencolor("blue")
                turtle.fd(38)
            elif i == '=':
                turtle.write('日',font=("Arial", 18, "normal"))
                turtle.pencolor("purple")
                turtle.fd(38)
            elif i=='$':
                turtle.write("时",font=("Arial",18,"normal"))
                turtle.pencolor("pink")
                turtle.fd(40)
            elif i=='/':
                turtle.write("分",font=("Arial",18,"normal"))
                turtle.fd(40)    
            else:
                drawDigit(eval(i))
     
     
    def main():
        turtle.setup(1200,350,200,200)
        turtle.speed(100)
        turtle.pensize(5)
        turtle.penup()
        turtle.fd(-5
    00)
        turtle.hideturtle()
        drawData(datetime.datetime.now().strftime('%Y-%m+%d=%H$%M/'))
        turtle.mainloop()
    main()
    

      

  • 相关阅读:
    leetcode56 合并区间(Medium)
    leetcode215 数组中的第k大元素(Medium)
    leetcode76 最小覆盖子串(Hard)
    leetcode75 颜色分类(Medium)
    leetcode64 最小路径和(Medium)
    Android 开发技巧
    Android 常用开源代码整理
    Android 屏幕尺寸知识
    Intellij IDEA 常用 设置 及 快捷键 (持续更新)
    Gradle Maven 依赖管理
  • 原文地址:https://www.cnblogs.com/hewa123-/p/13837954.html
Copyright © 2020-2023  润新知