吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 2282|回复: 7
收起左侧

[Python 转载] 教小朋友写的动态时钟_代码冗余没有优化

  [复制链接]
Eric_zhao 发表于 2021-11-7 11:09
[Python] 纯文本查看 复制代码
001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
053
054
055
056
057
058
059
060
061
062
063
064
065
066
067
068
069
070
071
072
073
074
075
076
077
078
079
080
081
082
083
084
085
086
087
088
089
090
091
092
093
094
095
096
097
098
099
100
101
102
103
104
import turtle
from datetime import datetime
import random
turtle.mode('logo')
turtle.tracer(False)
#turtle.bgpic('bac2.gif')
#设置时间
#算法 == 数学
turtle.colormode(255)
def color(): 
    r = random.randint(0,255)
    g = random.randint(0,255)
    b = random.randint(0,255)
    c = (r,g,b)
    return c
 
 
def Clock():
    turtle.clear()
    shijian = datetime.now() 
    print(shijian)
    h = shijian.hour
    m = shijian.minute
    s = shijian.second
    print(h,m,s)
    #h = 360/12 =30
    #m = 360/60 = 6
    #s = 360/60 = 6
    turtle.colormode(255)
    turtle.bgcolor(0,0,0)
    #时钟
    turtle.pencolor(144, 238, 144
    turtle.pensize(20
    turtle.pu() 
    turtle.goto(0,0)
    turtle.pd() 
    turtle.seth(360-h*3-90)
    turtle.fd(100)
    #分钟
    turtle.pencolor(135, 206, 250
    turtle.pensize(12
    turtle.pu() 
    turtle.goto(0,0)
    turtle.pd() 
    turtle.seth(m*6)
    turtle.fd(120)
    #秒钟
    turtle.seth(s*6)
    turtle.pencolor(69, 63, 127
    turtle.pensize(5
    turtle.pu() 
    turtle.goto(0,0)
    turtle.pd() 
    turtle.seth(s*6)
    turtle.fd(150)
    x = 160
    turtle.pensize(10)
    for i in range(4):
        turtle.pencolor(color())
        turtle.pu() 
        turtle.goto(x,0)
        turtle.pd()    
        turtle.seth(0)
        turtle.circle(x)
        x+=5
    for i in range(1,13):
        turtle.pu()
        turtle.seth(30*(i-1)+28)
        turtle.goto(-10,-10)
        turtle.fd(200)
         
        turtle.pd()    
        #turtle.seth(0)
        turtle.write(i,font = (None,20))   
    turtle.pensize(5)
    for i in range(60):
        turtle.pu()
        turtle.seth(6*(i)+28)
        turtle.goto(0,0)
        turtle.fd(150)
         
        turtle.pd()    
        #turtle.seth(0)
        turtle.fd(5)   
    turtle.ontimer(Clock,1000)
    turtle.update()
    t1 = '游人记得承平事'
    t2 = '暗喜风光似昔年'
    turtle.pu() 
    turtle.goto(-140,30)
    turtle.pd()  
    turtle.color(color())
    turtle.write(t1,font=(None,30))
    turtle.pu() 
    turtle.goto(-140,-30)
    turtle.pd() 
    turtle.color(color())
    turtle.write(t2,font=(None,30))
     
 
 
Clock()
 
turtle.done()
clock16.png

免费评分

参与人数 5吾爱币 +11 热心值 +4 收起 理由
zxczzz + 1 我很赞同!
lfm333 + 1 + 1 热心回复!
a199999 + 1 + 1 热心回复!
苏紫方璇 + 7 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!
毛新航 + 1 + 1 用心讨论,共获提升!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

1056647302 发表于 2021-11-7 15:58
谢谢分享!
a199999 发表于 2021-11-7 16:00
sam喵喵 发表于 2021-11-7 16:57
lfm333 发表于 2021-11-7 17:27
感谢分享
 楼主| Eric_zhao 发表于 2021-11-7 18:28
sam喵喵 发表于 2021-11-7 16:57
时针和分针要是不停得动,你就穿越咯

哈哈哈,盯一个小时看看
hshcompass 发表于 2021-11-7 20:29
谢谢分享
zph56789 发表于 2021-11-8 10:09
感谢楼主
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2025-5-29 02:36

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表