七段数码管绘制

#七段数码管绘制
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 else t.penup()
t.fd(40)
drawGap();
t.right(90)
def drawDigit(digit): #根据数字绘制七段数码管:如下七段: 1,2,3,4,5,6,7
drawLine(True) if digit not in [0,1,7] else drawLine(False) #1
drawLine(True) if digit not in [2 ] else drawLine(False) #2
drawLine(True) if digit not in [1,4,7] else drawLine(False) #3
drawLine(True) if digit not in [1,3,4,5,7,9] else drawLine(False) #4
t.left(90)
drawLine(True) if digit not in [1,2,3,7] else drawLine(False) #5
drawLine(True) if digit not in [4,1] else drawLine(False) #6
drawLine(True) if digit not in [5,6] else drawLine(False) #7
t.left(180);t.penup();
t.fd(10) #换个位置输出下一个字符,间隔
def drawDate(s):
t.pencolor('red')
for i in s:
if i=='-':
t.write('年',font=('Arial',18,'normal'))
t.pencolor('green')
t.fd(30)
elif i=='=':
t.write('月',font=('Arial',18,'normal'))
t.pencolor('blue')
t.fd(30)
elif i=='+':
t.write('日', font=('Arial', 18, 'normal'))
t.fd(30)
else:
drawDigit(eval(i)) #通过eval()把字符串转换成单个数字
def main():
t.setup(800,400)
t.penup()
t.fd(-300) #将起点挪到画布的左边
t.pensize(6)
drawDate(T.strftime('%Y-%m=%d+',T.gmtime()))#时间函数strftime返回的是字符串
# drawDate('0123456789')
t.hideturtle() #隐藏画笔的形状
t.done()
main()

转载于:https://www.cnblogs.com/oycc2000/p/11234256.html

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值