繪製七段數碼管

2021-09-02 11:09:09 字數 1992 閱讀 6601

# 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()

執行效果圖如下:

12.02 python學習**

七段數碼管繪製

步驟1 繪製單個數字對應的數碼管 步驟2 獲得一串數字,繪製對應的數碼管 步驟2 獲得當前系統時間,繪製對應的數碼管 步驟1 繪製單個數字對應的數碼管 基本問題是繪製一條線,可將其定義為乙個基本函式 def drawline draw turtle.pendown if draw else turt...

七段數碼管繪製

七段數碼管繪製 import turtle as t import time as t def drawgap 繪製數碼管的間隔 t.penup t.fd 5 def drawline draw 繪製單段數碼管,draw為true時,則實畫 drawgap t.pendown if draw els...

七段數碼管繪製 C

描述 根據七段數碼管繪製例項的思路,繪製創意的內容,內容不限 風格不限。例如 用七段數碼管繪製倒計時效果 繪製有一定風格的七段數碼管。解析 import turtle as t import datetime defdrawgap t.penup t.fd 5 defdrawline draw dr...