使用Python的turtle进行七段数码管的绘制(MOOC精品课程内容)
问题分析
刚刚开始学习Python的我们大都对Python的turtle绘图十分感兴趣,诚然,这是一组十分有效的绘图工具,而我们常见的交通灯是使用七段“灯管”来表示0-9的数字的,这是一种很醒目也很节约材料的方式,那么我们如何使用Python语言,来实现绘制“数字”的过程呢?
代码实现
1.绘制单段数码管
def drawLine(draw):
drawGap()#ps:就是让年月日之间出现间隔的函数...
turtle.pendown() if draw else turtle.penup()
turtle.fd(40)
drawGap()#ps:就是让年月日之间出现间隔的函数...
turtle.right(90)
(这里的drawGap()函数会马上出现的)
2.根据数字绘制七段数码管
def drawDight(dight):#画数字
drawLine(True) if dight in [2, 3, 4, 5, 6, 8, 9] else drawLine(False)
drawLine(True) if dight in [0, 1, 3, 4, 5, 6, 7, 8, 9] else drawLine(False)
drawLine(True) if dight in [0, 2, 3, 5, 6, 8, 9] else drawLine(False)
drawLine(True) if dight in [0, 2, 6, 8] else drawLine(False)
turtle.left(90)
drawLine(True) if dight in [0, 4, 5,