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

7段数码管绘制

时间:2023-11-21 18:11:06浏览次数:32  
标签:turtle False drawLine 绘制 else 数码管 fd True

import turtle, datetime
import time
def drawGap():
    turtle.penup()
    turtle.fd(5)
def drawLine(draw):
    drawGap()
    turtle.pendown() if draw else turtle.penup()
    turtle.fd(40)
    drawGap()
    turtle.right(90)
def drawDigit(d):
    drawLine(True) if d in [2, 3, 4, 5, 6, 8, 9] else drawLine(False)
    drawLine(True) if d in [0, 1, 3, 4, 5, 6, 7, 8, 9] else drawLine(False)
    drawLine(True) if d in [0, 2, 3, 5, 6, 8, 9] else drawLine(False)
    drawLine(True) if d in [0, 2, 6, 8] else drawLine(False)
    turtle.left(90)
    drawLine(True) if d in [0, 4, 5, 6, 8, 9] else drawLine(False)
    drawLine(True) if d in [0, 2, 3, 5, 6, 7, 8, 9] else drawLine(False)
    drawLine(True) if d 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("orange")
            turtle.fd(40)
        elif i == '*':
          turtle.write('星期', font=("Arial", 18, "normal"))
        else:
            drawDigit(eval(i))
def main():
    turtle.setup(800, 350, 200, 200)
    turtle.penup()
    turtle.fd(-350)
    turtle.pensize(5)
    drawDate(time.strftime('%H-%M=%S+%*w', time.localtime()))
    turtle.hideturtle()
main()

 

标签:turtle,False,drawLine,绘制,else,数码管,fd,True
From: https://www.cnblogs.com/FXY-/p/17847244.html

相关文章

  • react中绘制饼图基础例子
    使用interval标记和theta坐标系来绘制饼图 radius:标签相对于饼图圆心的距离.label()中的text指定了一个回调函数,可以设置标签,其中d是当前项数据,i是当前项的索引,data是全部的数据,注意回调函数要有返回值。实现效果: import{Chart}from'@antv/g2'importReactfrom'......
  • 7段数码管绘制
    importturtleimportdatetimeimporttimedefdraw_gap():#画数码间隔turtle.penup()turtle.fd(5)defdraw_line(draw):#画单段数码管draw_gap()turtle.pendown()ifdrawelseturtle.penup()turtle.fd(40)draw_gap()turtle.r......
  • 7段数码管绘制
       ......
  • 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段数码管绘制
    importturtleimportdatetimeimporttimedefdraw_gap():#绘制数码间隔turtle.penup()turtle.fd(5)defdraw_line(draw):#绘制单段数码管draw_gap()turtle.pendown()ifdrawelseturtle.penup()turtle.fd(40)draw_gap()turtle.right(90)def......
  • 7段数码管绘制
    要求:画出,系统时间。具体包括:小时,分,秒,星期。 importturtleastimporttimea=time.strftime('%a',time.localtime())ifa=='Mon':c=1elifa=='Tue':c=2elifa=='Wed':c=3elifa=='Thu':c=4elif......
  • 七段数码管显示时间
    importturtleimportdatetimeimporttimedefdraw_gap():#绘制数码间隔turtle.penup()turtle.fd(5)defdraw_line(draw):#绘制单段数码管draw_gap()turtle.pendown()ifdrawelseturtle.penup()turtle.fd(40)draw_gap()turt......
  • 数码管
    #数码管显示系统年,月,日,时间1importturtle,datetime2defdrawling(draw):34turtle.pendown()ifdrawelseturtle.penup()5turtle.fd(40)6turtle.right(90)78defdraworigin(d):9drawling(True)ifdin[2,3,4,5,6,8,9]elsedr......
  • 7段数码管绘制
    7段数管码代码运行22信计1班34号代码#e7.2DrawSevenSegDisplay.pyimportturtle,datetimedefdrawGap():#绘制数码管间隔turtle.penup()turtle.fd(5)defdrawLine(draw):#绘制单段数码管drawGap()turtle.pendown()ifdrawelseturtle.penup()turtle......
  • 七段数码管绘制
    importturtle,datetimedefdrawGap():#绘制数码管间隔turtle.penup()turtle.fd(5)defdrawLine(draw):#绘制单段数码管drawGap()turtle.pendown()ifdrawelseturtle.penup()turtle.fd(40)drawGap()turtle.right(90)defdrawDigit(d):#根据......