1. 程式人生 > >繪製七段數碼管

繪製七段數碼管

文章目錄

Code

# Seven Digits Draw V1.0
# 第一,繪製線;
# 第二,繪製七段數碼管組成的數字;
#第三,繪製優化數碼管間距;
#第四,繪製多組數字;
#第五,獲取系統時間;
#第六,主函式執行程式。


# 程式碼如下
import turtle as t
import time

def DrawLine(draw):
    DrawGap()
    t.pendown() if draw else t.penup()
    t.fd(45)
    DrawGap()
    t.right(90)
#Drawline()
def DrawDigits(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","7","8","9"] else DrawLine(False)
    t.left(180)
    t.fd(20)
#DrawDigits()
def DrawDate():
    date = Gettime()
    t.pencolor("red")
    for num in date:
        if num == "-":
            t.write("年",font=("Arial",18,"normal"))
            t.pencolor("green")
            t.fd(50)
        elif num == "=":
            t.write("月",font=("Arial",18,"normal"))
            t.pencolor("blue")
            t.fd(50)
        elif num == "+":
            t.write("日",font=("Arial",18,"normal"))
        else:
            DrawDigits(num)
#DrawDate()
def DrawGap():
    t.penup()
    t.fd(2.5)
#DrawGap 優化線間距
def Gettime():
    date = time.strftime("%Y-%m=%d+",time.gmtime())
    return date
#Gettime 獲取系統時間
def main():
    t.setup(800,350,200,200)
    t.penup()
    t.bk(350)
    t.pensize(3)
    DrawDate()
    t.hideturtle()
main()

Explanation

執行效果圖如下:
七段數碼管繪製

Remarks

12.02 Python學習程式碼