zoukankan      html  css  js  c++  java
  • #Python语言程序设计Demo

    Python设计七段数码管绘制

    单个数码管效果:

    设计总数码管效果:

    Pyhton 编程:

    #七段数码管绘制
    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()))
    #    drawDate('0123456789')
        t.hideturtle()   #隐藏画笔的形状
        t.done()
    main()

    1、先测试各位数字是否正常显示:

       在main()中设置下列代码:

    #   drawDate(T.strftime('%Y-%m=%d+',T.gmtime()))
    drawDate('0123456789')

    显示结果:

     

    说明没有问题!

    2、具体在main()中再略加修改:

     drawDate(T.strftime('%Y-%m=%d+',T.gmtime()))
        #drawDate('0123456789')

    显示结果:

      

  • 相关阅读:
    游戏编程模式之事件队列模式
    游戏编程模式之组件模式
    游戏编程模式之类型对象模式
    游戏编程模式之父类沙盒模式
    游戏编程模式之字节码模式
    游戏人工智能简介
    游戏编程模式之更新模式
    游戏编程模式之游戏循环
    .vimrc配置文件 + gvim 运行 gnome-terminal 完成后等待
    js 批量移除steam游戏 移除用户凭证中免费获取的物品
  • 原文地址:https://www.cnblogs.com/zhazhaacmer/p/9750234.html
Copyright © 2011-2022 走看看