python

#1、导入库模块
from turtle import *        #其方法前不能加库名
import random 
import time

#2、绘制单段间隔
def drawGap():
    penup()
    fd(5)
    

#3、绘制单段数码管
def drawLine(draw):
    drawGap()       #调用函数
    if draw:
        pendown()
    else:
        penup()
    fd(20)
    drawGap()
    right(90)     #将画笔向右旋转90度
    

#4、根据数字绘制七段数码管
def drawDigit(digit):
    #第1段
    pencolor(random.random(),random.random(),random.random())
    drawLine(True) if digit in [2,3,4,5,6,8,9] else drawLine(False)  #用条件表达式判断
    #第2段
    pencolor(random.random(),random.random(),random.random())
    drawLine(True) if digit in [0,1,3,4,5,6,7,8,9] else drawLine(False)
    #第3段
    pencolor(random.random(),random.random(),random.random())
    drawLine(True) if digit in [0,2,3,5,6,8,9] else drawLine(False)
    #第4段
    pencolor(random.random(),random.random(),random.random())
    drawLine(True) if digit in [0,2,6,8] else drawLine(False)
    left(90)        #将画笔向 左旋转90度
    #第5段
    pencolor(random.random(),random.random(),random.random())
    drawLine(True) if digit in [0,4,5,6,8,9] else drawLine(False)
    #第6段
    pencolor(random.random(),random.random(),random.random())
    drawLine(True) if digit in [0,2,3,5,6,7,8,9] else drawLine(False)
    #第7段
    pencolor(random.random(),random.random(),random.random())
    drawLine(True) if digit not in [5,6] else drawLine(False)
    
    right(180)    #将画笔旋转180度重新调整为前进的方向
    penup()    #设置画笔飞行模式
    fd(20)    #将画笔向前行进20像素
   

#5、获得要输出的数字
def drawData(date):
    for i in date:
        if i=='-':
            write('年',font=("楷体",20,"normal"))
            fd(40)    #画笔写完字之后向前行进40像素
        elif i=='=':
            write('月',font=("楷体",20,"normal"))
            fd(40)
        elif i=='+':
            write('日',font=("楷体",20,"normal"))
        else:
            drawDigit(eval(i))
    

#6、主函数(设置画布与画笔等)
def main():
    setup(850,350)   #设置画布大小
    bgcolor('black')  #画布背景颜色
    penup()     #飞行模式
    fd(-350)           #向左行进350像素
    pendown()
    pensize(5)
    speed(200)    #画笔速度
    #date = input('请输入您的生日:')    #获取系统

   date=time.strftime('%Y-%m=%d+')

   drawData(date)

   hideturtle()

  done()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

m0_68669533

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值