用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - python代码库

draw present time——画出当前时间

2019-09-28 作者: WELT举报

[python]代码库

import turtle,time
import random

def drawLine(draw):
    colors = ['red','black', 'green', 'blue', 'yellow', 'purple','mauve','scarlet']
    a=random.randint(1,8)
    turtle.pencolor(colors[8%a])
    turtle.penup()
    turtle.fd(5)
    turtle.pendown() if draw else turtle.penup()
    turtle.fd(35)
    turtle.penup()
    turtle.fd(5)
    turtle.right(90)


def drawDigts(n):
    drawLine(True) if n in ['2', '3', '4', '5', '6', '8', '9'] else drawLine(False)
    drawLine(True) if n in ['0', '1', '3', '4', '5', '6', '7', '8', '9'] else drawLine(False)
    drawLine(True) if n in ['0', '2', '3', '5', '6', '8', '9'] else drawLine(False)
    drawLine(True) if n in ['0', '2', '6', '8'] else drawLine(False)
    turtle.left(90)
    drawLine(True) if n in ['0', '4', '5', '6', '8', '9'] else drawLine(False)
    drawLine(True) if n in ['0', '2', '3', '5', '6', '7', '8', '9'] else drawLine(False)
    drawLine(True) if n in ['0', '1', '2', '3', '4', '7', '8', '9'] else drawLine(False)
    turtle.left(180)
    turtle.penup()
    turtle.fd(10)


def drawDate(date):
    for i in range(0,len(date)):
        drawDigts(date[i])
        if date[i]=='-':
            turtle.penup()
            turtle.right(90)
            turtle.fd(30)
            turtle.left(90)
            turtle.pendown()
            turtle.write('年',align='center',font=('Arial',52,'normal',))
            turtle.penup()
            turtle.left(90)
            turtle.fd(30)
            turtle.right(90)
            turtle.fd(60)
        elif date[i]=='+':
            turtle.penup()
            turtle.right(90)
            turtle.fd(30)
            turtle.left(90)
            turtle.pendown()
            turtle.write('月',font=('Arial',52,'normal'))
            turtle.penup()
            turtle.left(90)
            turtle.fd(30)
            turtle.right(90)
            turtle.fd(60)
        elif date[i]=='=':
            turtle.penup()
            turtle.right(90)
            turtle.fd(30)
            turtle.left(90)
            turtle.pendown()
            turtle.write('日',font=('Arial',52,'normal'))
            turtle.penup()
            turtle.left(90)
            turtle.fd(30)
            turtle.right(90)
            turtle.fd(60)

turtle.setup(1000,600,500,500)
turtle.hideturtle()
turtle.penup()
turtle.bk(380)
date=time.strftime('%Y-%m+%d=',time.gmtime())
turtle.pendown()
drawDate(date)
turtle.exitonclick()

[代码运行效果截图]


draw present time——画出当前时间


网友评论    (发表评论)

共1 条评论 1/1页

发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...