Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3657358
  • 博文数量: 365
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 2522
  • 用 户 组: 普通用户
  • 注册时间: 2019-10-28 13:40
文章分类

全部博文(365)

文章存档

2023年(8)

2022年(130)

2021年(155)

2020年(50)

2019年(22)

我的朋友

分类: Python/Ruby

2021-10-29 17:11:39

import datetime

import turtle

name = []

def drawLine(draw):  # 绘制单段数码管

    turtle.pendown() if draw else turtle.penup()

    turtle.fd(40)

    turtle.right(90)

def drawLine1(draw):  # 绘制单段数码管1

    turtle.pendown() if draw else turtle.penup()

    turtle.fd(20)

def drawtdown1(draw):  # 斜线

    turtle.pendown() if draw else turtle.penup()

    turtle.fd(44.7)

def drawDigit(digit):  # 根据数字绘制七段数码管

    # 1

    drawLine1(True) if digit in [2, 4, 5, 6, 8, 9, 'A', 'E', 'F', 'H',  'K', 'P', 'R', 'S'] else drawLine1(False)

    # 2

    drawLine1(True) if digit in [2, 3, 4, 5, 6, 8, 9,'F', 'A','B','G','H','P,'R',S'] else drawLine1(False)

    # 3

    turtle.right(90)

    drawLine(True) if digit in [0, 1, 3, 4, 5, 6, 7, 8, 9, 'A', 'B', 'D', 'G', 'H', 'J', 'M', 'N' , 'O', 'Q', 'S', 'U', 'W'] else drawLine(False)

    # 4

    drawLine(True) if digit in ['L',0, 2, 3, 5, 6, 8, 9, 'B', 'C', 'D', 'E', 'G', 'I', 'U','J', 'O', 'Q', 'S', 'Z'] else drawLine(False)

    # 5

    drawLine(True) if digit in ['L',0, 2, 6, 8, 'A', 'C' , 'E' , 'F' , 'G', 'H' , 'J' , 'K' , 'L' , 'M' , 'N' ,'O' , 'P' , 'Q' ,'R' , 'U' , 'V' , 'W'] else drawLine(False)

    # 6笔(因为会右转,这里调节第五笔为向上直线)

    turtle.left(90)

    drawLine(True) if digit in ['L',0, 4, 5, 6, 8, 9, 'A','C','E','F','G','H','K','M','N','O','P','Q','R','S','U','V','W'] else drawLine(False)

    # 7

    drawLine(True) if digit in [0, 2, 3, 5, 6, 7, 8, 9, 'A','B','C','D','E','F','G','O','P','Q','R','I','S','T','Z'] else drawLine(False)

    # 8

    drawLine(True) if digit in [0, 1, 2, 3, 4, 7, 8, 9, 'A','B','D','H','J','M','N','O','P','Q','R','U','W'] else drawLine(False)

    # 9

    turtle.left(90)

    turtle.penup()

    turtle.fd(40)

    turtle.right(90 + 63.4)

    drawtdown1(True) if digit in ['K','N','Q','K','N','Q','R','W','X'] else drawtdown1(False)  

    # 10********************

    drawtdown1(True) if digit in ['M','N','X','Y'] else drawtdown1(False)

    # 11********************

    turtle.right(90 + 26.6)

    turtle.penup()

    turtle.fd(20)

    turtle.right(90)

    drawLine(True) if digit in ['B','D','I','T'] else drawLine(False)

    # 12***********

    turtle.left(90)

    drawLine(True) if digit in ['B','D','I','T','Y'] else drawLine(False)

    # 13

    turtle.penup()

    turtle.fd(20)

    turtle.right(90 + 26.6)

    drawtdown1(True) if digit in ['V','X','Z','W', 0] else drawtdown1(False)

    # 14

    drawtdown1(True) if digit in ['M','V','X','Y','Z','K', 0, 1] else drawtdown1(False)

    turtle.right(90 + 63.4)

    turtle.penup()

    turtle.fd(40)

    turtle.left(90)

    turtle.fd(20)

def drawDate(date):

    turtle.pencolor("black")

    for i in date:

        if i == '-':

            turtle.write('', font=("Arial", 25, "normal"))

            turtle.pencolor("black")

            turtle.fd(40)

        elif i == '=':

            turtle.write('', font=("Arial", 25, "normal"))

            turtle.pencolor("black")

            turtle.fd(40)

        elif i == '+':

            turtle.write('', font=("Arial", 25, "normal"))

        else:

            drawDigit(eval(i))

def drawname():

    #name = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']

    name = ['L', 'O', 'N', 'G',' ', 'T', 'A', 'O']

    #name = [ 'I','  ','L','O','V','E', ' ',  'Y','O','U']

    for i in name:

        drawDigit(i)

def main():

    turtle.setup(800, 350, 200, 200)

    turtle.penup()

    turtle.goto(-300, 50)

    turtle.pensize(5)

    turtle.pencolor("black")

    turtle.speed(0)#这个让乌龟跑快点,外汇跟单gendan5.com慢慢爬真的难受,想慢点的同志把这个注释就行

    drawDate(datetime.datetime.now().strftime('%Y-%m=%d+'))

    turtle.penup()

    turtle.goto(-200, -100)

    turtle.pencolor('red')

    drawname()

    turtle.hideturtle()

    turtle.exitonclick()#画完不关闭画布,点击关闭

main()

阅读(1910) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~