首页 > 其他分享 >7段数码管绘制

7段数码管绘制

时间:2023-11-23 17:56:46浏览次数:33  
标签:turtle digit False drawLine True else 数码管 绘制

import turtle, datetime
def drawLine(draw): # 绘制单段数码管
turtle.pendown() if draw else turtle.penup()
turtle.fd(40)
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(30)

def drawDate(date): # 获得要输出的数字
for i in range(len(date)):
drawDigit(eval(date[i]))
if 3<=i<=4:#改变笔的颜色
turtle.pencolor('red')
elif 5<=i<=6:
turtle.pencolor('orange')
elif 7<=i<=8:
turtle.pencolor('green')
elif 9<=i<=10:
turtle.pencolor('yellow')
else:
turtle.pencolor('pink')
def main():
turtle.setup(1024, 600, 200, 200)
turtle.pencolor('pink')
turtle.penup()
turtle.fd(-500)
turtle.pensize(5)
drawDate(datetime.datetime.now().strftime('%Y%m%d%H%M%S'))
turtle.hideturtle()
main()

标签:turtle,digit,False,drawLine,True,else,数码管,绘制
From: https://www.cnblogs.com/slowdowna002/p/17852145.html

相关文章

  • 七段数码管绘制
      importturtle,datetime#定义一个,用于绘制代码管的间隙defdraw_gap():turtle.penup()turtle.forward(5)#定义一个函数,用于绘制一段代码管,这里传入的参数输一个bool类型defdraw_line(draw):draw_gap()turtle.pendown()ifdrawelseturtle.penup()......
  • 7段数码管绘制(小时,分,秒)
    7段数码管绘制(小时,分,秒)python代码:#七段数码管的绘制.pyfromturtleimport*#调用turtle、random、time库fromrandomimport*importtimedefdrawGap():penup()#提笔fd(5)defdrawLine(draw):drawGap()ifdraw:#除了七段数码管提笔,其......
  • 数码管问题
    importturtle,datetimedefdrawGap(): #绘制数码管间隔  turtle.penup()  turtle.fd(5)defdrawLine(draw): #绘制单段数码管  drawGap()  turtle.pendown()ifdrawelseturtle.penup()  turtle.fd(40)  drawGap()  turtle.right......
  • 7段数码管绘制
    7段数码管绘制运行代码importturtle,datetimedefdrawGap(): #绘制数码管间隔  turtle.penup()  turtle.fd(5)defdrawLine(draw): #绘制单段数码管  drawGap()  turtle.pendown()ifdrawelseturtle.penup()  turtle.fd(40)  draw......
  • 单片机+数码管
    利用8个数码管显示座位号+字母+学号后六位首先参考图参考程序可以了解到此程序实现了数码管显示OFF我们可以改的简单一点如下#include "reg51.h" //引入块unsigned char a_code[]{0x3f,0x71,0x00}; //共阴级数码管字段编码,我们选取重要的几个unsigned char a......
  • 7段数码管绘制
    importturtle,datetimedefdrawLine(draw): turtle.pendown()ifdrawelseturtle.penup()turtle.fd(40)turtle.right(90)defdrawDigit(digit): drawLine(True)ifdigitin[2,3,4,5,6,8,9]elsedrawLine(False)drawLine(True)ifdigitin......
  • 七段数码管绘制
    #22信计2向悦17号importturtle,datetime#3107defdrawGap():turtle.penup()turtle.fd(5)defdrawLine(draw): drawGap()turtle.pendown()ifdrawelseturtle.penup()turtle.fd(40)drawGap()turtle.right(90)defdrawDigit(d): drawLine(Tr......
  • 七段数码管绘制
    importturtle,datetimedefdrawLine(draw):turtle.pendown()ifdrawelseturtle.penup()turtle.fd(40)turtle.right(90)defdrawDigit(d):drawLine(True)ifdin[2,3,4,5,6,8,9]elsedrawLine(False)drawLine(True)ifdin[0,1,3,4,5,6,7,8,9......
  • 7段数码管绘制
    importturtle,datetimedefdrawGap():#绘制数码管间隔turtle.penup()turtle.fd(5)defdrawLine(draw):#绘制单段数码管drawGap()turtle.pendown()ifdrawelseturtle.penup()turtle.fd(40)drawGap()turtle.right(90)defdrawDigit(d):#......
  • 7段数码管绘制
    7段数码管绘描述:画出系统时间。具体包括:年,月,日,小时,分,秒。python代码:importturtle,datetimedefdrawGap():#绘制数码管间隔turtle.penup()turtle.fd(5)defdrawLine(draw):#绘制单段数码管drawGap()turtle.pendown()ifdrawelseturtle.penup......