importturtle, time
def drawgap():turtle.speed(0) #
設定畫筆速度 「fastest」:0 "fast":10 "normal":6 "slow":3 "slowest":1# turtle.turtle().screen.delay(0) #畫筆速度無延遲turtle.penup()turtle.fd(5)
def drawline(draw): #
繪製單段數碼管drawgap()turtle.speed(0)# turtle.turtle().screen.delay(0)turtle.pendown() if draw else turtle.penup()turtle.fd(40)drawgap()turtle.right(90)
def drawdigit(digit): #
根據數字繪製七段數碼管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)turtle.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)turtle.left(180)turtle.penup() # 為繪製後續數字確定位置turtle.fd(20) # 為繪製後續數字確定位置
def drawdate(date):turtle.pencolor("
red")for i in date:if i == '
+':turtle.write("
年", font=("
arial
", 18, "
normal
"))turtle.pencolor("
green
")turtle.fd(40)elif i == '
-':turtle.write("
月", font=("
arial
", 18, "
normal
"))turtle.pencolor("
blue
")turtle.fd(40)elif i == '
*':turtle.write("
日", font=("
arial
", 18, "
normal
"))turtle.pencolor("
red")turtle.fd(70)
elif i == '
$':turtle.write("
時", font=("
arial
", 18, "
normal
"))turtle.pencolor("
green
")turtle.fd(40)elif i == '
&':turtle.write("
分", font=("
arial
", 18, "
normal
"))turtle.pencolor("
blue
")turtle.fd(40)elif i == '
@':turtle.write("
秒", font=("
arial
", 18, "
normal
"))else
:drawdigit(eval(i))
def main(): #
主函式turtle.setup(1600, 1000, 0, 0)turtle.penup()turtle.left(90)turtle.fd(200)turtle.right(90)turtle.fd(-600)turtle.pensize(5)drawdate(time.strftime("%y+%m-%d*%h$%m&%s@", time.localtime()))turtle.hideturtle()turtle.done()
7段數碼管繪製
import turtle,datetime def drawgap 繪製數碼管間隔 turtle.penup turtle.fd 5 def drawline draw 繪製單段數碼管 drawgap turtle.pendown if draw else turtle.penup turtle....
7段數碼管繪製
import turtle,datetime def drawgap 繪製數碼管間隔 turtle.penup turtle.fd 5 def drawline draw 繪製單段數碼管 drawgap turtle.pendown if draw else turtle.penup turtle....
7段數碼管繪製
import turtle,time defdrawgap turtle.speed 0 設定畫筆速度 fastest 0 fast 10 normal 6 slow 3 slowest 1 turtle.turtle screen.delay 0 畫筆速度無延遲 turtle.penup turt...