• python(10)---七段数码管(2)


      今天根据网上的教程修改了七段数码管的程序,引入了time库函数,这样程序可以

    根据系统的时间画出七段数码管了。废话不多说了,直接上程序:

     1 #!/usr/bin/env python3
     2 # -*- coding: utf-8 -*-
     3 #Segement7_2.py
     4 import turtle,time
     5 def drawGap():
     6     turtle.penup()
     7     turtle.fd(5)
     8 def drawline(draw):
     9     drawGap()
    10     turtle.pendown() if draw else turtle.penup()
    11     turtle.fd(40)
    12     drawGap()
    13     turtle.right(90)
    14 def drawdigit(digit):
    15     drawline(True) if digit in [2,3,4,5,6,8,9] else drawline(False)
    16     drawline(True) if digit in [0,1,3,4,5,6,7,8,9] else drawline(False)
    17     drawline(True) if digit in [0,2,3,5,6,8,9] else drawline(False)
    18     drawline(True) if digit in [0,2,6,8] else drawline(False)
    19     turtle.left(90)
    20     drawline(True) if digit in [0,4,5,6,8,9] else drawline(False)
    21     drawline(True) if digit in [0,2,3,5,6,7,8,9] else drawline(False)
    22     drawline(True) if digit in [0,1,2,3,4,7,8,9] else drawline(False)
    23     turtle.left(180)
    24     turtle.penup()
    25     turtle.fd(20)
    26 def drawdate(date):
    27     turtle.pencolor("red")
    28     for i in date:
    29         if i=='-':
    30             turtle.write("",font=("Arial",18,"normal"))
    31             turtle.pencolor("green")
    32             turtle.fd(40)
    33         elif i=='=':
    34             turtle.write("",font=("Arial",18,"normal"))
    35             turtle.pencolor("blue")
    36             turtle.fd(40)
    37         elif i=='+':
    38             turtle.write("",font=("Arial",18,"normal"))
    39         else:
    40             drawdigit(eval(i))
    41 def main():
    42     turtle.setup(800,350,200,200)
    43     turtle.penup()
    44     turtle.fd(-300)
    45     turtle.pensize(5)
    46     drawdate(time.strftime("%Y-%m=%d+",time.gmtime()))
    47     #drawdate('20181010')
    48     turtle.hideturtle()
    49     turtle.done()
    50 main()
    segment7_2

      

  • 相关阅读:
    Three.js源码阅读笔记4
    算法导论11.动态规划上
    leetcode刷题笔录1
    JavaScript的模块化:封装(闭包),继承(原型)
    leetcode刷题笔录5
    算法导论1.排序算法
    算法导论3.递归部分习题选
    Three.js Demo源码分析1.MorphTargets与BufferGeometry
    算法导论10.顺序统计树与区间树习题
    算法导论4.随机快速排序与线性时间排序
  • 原文地址:https://www.cnblogs.com/xuelanga000/p/12651190.html
Copyright © 2020-2023  润新知