首页 > 其他分享 >7段数码管绘制

7段数码管绘制

时间:2022-12-08 19:15:26浏览次数:41  
标签:digit Arial drawLine else 数码管 fd font 绘制

# 绘制七段数码管
import turtle as t
import time


def drawGap():      # 绘制数码管间隔的函数
    t.penup()
    t.fd(5)


def drawLine(draw):     # 单个线段的绘制
    drawGap()       # 在线段绘制前,分隔一段距离
    t.pendown() if draw else t.penup()
    t.fd(40)
    drawGap()       # 在线段绘制后,分隔一段距离
    t.right(90)
    return


def drawDigit(digit):       # 数字0-9对应的七段数码管的绘制
    drawLine(True) if digit in [2, 3, 4, 5, 6, 8, 9] else drawLine(False)
    drawLine(True) if digit in [0, 1, 3, 4, 5, 6, 7, 8, 9] else drawLine(False)
    drawLine(True) if digit in [0, 2, 3, 5, 6, 8, 9] else drawLine(False)
    drawLine(True) if digit in [0, 2, 6, 8] else drawLine(False)
    t.left(90)
    drawLine(True) if digit in [0, 4, 5, 6, 8, 9] else drawLine(False)
    drawLine(True) if digit in [0, 2, 3, 5, 6, 7, 8, 9] else drawLine(False)
    drawLine(True) if digit in [0, 1, 2, 3, 4, 7, 8, 9] else drawLine(False)
    t.left(180)
    t.penup()
    t.fd(20)


def drawDate(date):     # 给定日期转化为数字,画出每个数字
    t.pencolor("red")
    for i in date:
        if i == "-":
            t.write("年", font=("Arial", 18, "normal"))
            t.pencolor("green")
            t.fd(40)
        elif i == "=":
            t.write("月", font=("Arial", 18, "normal"))
            t.pencolor("blue")
            t.fd(40)
        elif i == "+":
            t.write("日", font=("Arial", 18, "normal"))
        
        elif i == '/':
            t.write('时', font=("Arial", 18, "normal"))
            t.pencolor('green')
            t.fd(40)
        elif i == '!':
            t.write('分', font=("Arial", 18, "normal"))
            t.pencolor('blue')
            t.fd(40)
         
        elif i == '@':
            t.write('秒', font=("Arial", 18, "normal"))
            t.pencolor('black')
            t.fd(40)
        elif i == '$':
            t.write('星期', font=("Arial", 18, "normal"))
            t.pencolor('purple')
            t.fd(50)
        else:
            drawDigit(eval(i))
    t.exitonclick()
        
def main():
    t.setup(1366, 350, 0, 200)
    t.penup()
    t.fd(-600)
    t.pensize(5)
    drawDate(time.strftime("%Y-%m=%d+%H/%M!%S@$", time.gmtime()))
    t.hideturtle()
    t.done()


main()

 

标签:digit,Arial,drawLine,else,数码管,fd,font,绘制
From: https://www.cnblogs.com/xsj666/p/16967008.html

相关文章

  • Python7段数码管绘制
    #七段数码管绘制importturtleastimporttimeasTdefdrawGap():#绘制数码管的间隔t.penup()t.fd(5)defdrawLine(draw):#绘制单段数码管,draw为True时,则实......
  • Python 7段数码管绘制
    #七段数码管绘制importturtleastimporttimeasTdefdrawGap():#绘制数码管的间隔t.penup()t.fd(5)defdrawLine(draw):#绘制单段数码管,draw为True时,则实......
  • 7段数码管绘制
    代码如下: 1importturtle,datetime23defdrawGap():#绘制数码管间隔4turtle.penup()5turtle.fd(5)67defdrawLine(draw):#绘制单......
  • 7段数码管绘制
    importturtle,datetimedefdrawGap():#绘制数码管间隔turtle.penup()turtle.fd(5)defdrawLine(draw):#绘制单段数码管drawGap()turtle.pendown(......
  • 数码管绘制时间
    1importturtle2importdatetime34defdrawGap():#绘制数码管间隔5turtle.penup()6turtle.fd(1)78defdrawLine(draw):#绘制单段数......
  • 7段数码管绘制
    importturtle,datetimedefdrawGap():#绘制数码管间隔turtle.penup()turtle.fd(5)defdrawLine(draw):#绘制单段数码管drawGap()turtle.pendown......
  • 7段数码管绘制
    importturtle,datetimedefdrawGap():#绘制数码管间隔turtle.penup()turtle.fd(5)defdrawLine(draw):#绘制单段数码管drawGap()turtle.p......
  • 七段数码管控绘制
    代码如下:importturtle,datetimedefdrawGap():#绘制数码管间隔turtle.penup()turtle.fd(5)defdrawLine(draw):#绘制单段数码管drawGap()......
  • 7段数码管绘制python实验
    实验代码如下:1importturtle,time2defdrawGap():3turtle.penup()4turtle.fd(5)5defdrawLine(draw):#绘制单段数码管6drawGap()......
  • 7段数码管绘制 (2022年12月8日 14点38分)
    """7段数码管绘制"""importturtle,datetimedefdrawGap():#绘制数码管间隔turtle.penup()turtle.fd(5)defdrawLine(draw):#绘制单段数码管d......