用户:我就是旭日东升的那一米阳光查看:0 回复:0 评论:0 创建时间:2021-04-09T19:28:31
【作品展示】

【作品介绍】
学习
【作品源代码】
import turtle
from datetime import *
#up down 表示画笔抬起放下的过程,中间走了一定的步数,这里表示行走的过程
def Skip(step):
turtle.penup()
turtle.forward(step)
turtle.pendown()
#建立表针,
def mkHand(name, length):
turtle.reset()
Skip(-length*0.1)
turtle.begin_poly()
turtle.forward(length*1.1)
turtle.end_poly()
handForm = turtle.get_poly()
turtle.register_shape(name, handForm)
#建立秒针、分针、时针的旋转
def Init():
global secHand, minHand, hurHand, printer
turtle.mode("logo")
# 三种模式:standard,logo,world。 standard: 向右(朝东) 逆时针
# logo : 向上(朝北) 顺时针
mkHand("secHand", 135) # secHand表示名称秒针,135表示长度
mkHand("minHand", 125) # 分针,125长度
mkHand("hurHand", 90) # 时针,90长度
secHand = turtle.Turtle()
secHand.shape("secHand")
minHand = turtle.Turtle()
minHand.shape("minHand")
hurHand = turtle.Turtle()
hurHand.shape("hurHand")
for hand in secHand, minHand, hurHand:
hand.shapesize(1, 1, 3)
hand.speed(0)
printer = turtle.Turtle()
printer.hideturtle()
printer.penup()
#这里是绘制表盘内边一圈的点点
def SetupClock(radius):
turtle.reset() # 清空之前的内容
turtle.pensize(9) # 表示画笔的粗细
for i in range(60): # 60个点依次循环
Skip(radius)
if i % 5 == 0: # 如果是5的倍数,即为整点部分
turtle.forward(20)
Skip(-radius - 20)
Skip(radius + 20)
if i == 0:
turtle.write(int(12), align="center",
font=("Courier", 14, "bold"))
elif i == 30:
Skip(25)
turtle.write(int(i/5), align="center",
font=("Courier", 14, "bold"))
Skip(-25)
elif(i == 25 or i == 35):
Skip(20)
turtle.write(int(i/5), align="center",
font=("Courier", 14, "bold"))
Skip(-20)
else:
turtle.write(int(i/5), align="center",
font=("Courier", 14, "bold"))
Skip(-radius - 20)
else:
turtle.dot(5)
Skip(-radius)
turtle.right(6)
def week(t):
week = ["星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日"]
return week[t.weekday()]
#显示当前时间
def Date(t):
y = t.year
m = t.month
d = t.day
return "%s年%d月%d日" % (y, m, d)
#定义旋转的规则
def Tick():
t = datetime.today()
second = t.second+t.microsecond*0.000001
minute = t.minute+second/60.0
hour = t.hour+minute/60.0
secHand.setheading(6*second)
minHand.setheading(6 * minute)
hurHand.setheading(30 * hour)
turtle.tracer(False)
printer.forward(65)
printer.write(week(t), align="center", font=("Courier", 14, "bold"))
printer.back(130)
printer.write(Date(t), align="center",
font=("Courier", 14, "bold"))
printer.home()
turtle.tracer(True)
# 100ms后继续调用tick
turtle.ontimer(Tick, 100)
def main():
# 打开/关闭龟动画,并为更新图纸设置延迟。
turtle.tracer(False)
Init()
SetupClock(160)
turtle.tracer(True)
Tick()
turtle.mainloop()
if __name__ == "__main__":
main()
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn