源代码:
# coding=utf-8
import turtle
from datetime import *
# 由于表盘刻度不连续,需频繁抬起画笔,放下画笔
def skip(step):
turtle.penup() # 画笔抬起
turtle.forward(step) # 画笔移动step
turtle.pendown() # 画笔落下
# 建立表针,定制表针形状和名字
def make_hand(name, length):
turtle.reset()
skip(-length * 0.1) # 表针一端,过表盘中心一小段,开始绘制
turtle.begin_poly() # 开始记录多边形的第一个顶点。
turtle.forward(length * 1.1) # 设置表针长度,绘制表针
turtle.end_poly() # 停止记录多边形的顶点。当前的乌龟位置是多边形的最后一个顶点。将与第一个顶点相连。
handForm = turtle.get_poly() # 返回最后记录的形状
turtle.color('black')
turtle.register_shape(name, handForm)
# 三个表针初始化,实例化
def init_hand():
global sec_hand, min_hand, hou_hand, printer
# 重置Turtle指向北
turtle.mode("logo") # logo:向上(北) 顺时针 standard:向右(东) 逆时针
# 建立三个表针Turtle并初始化
make_hand("s