1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
| from turtle import * from datetime import *
def Skip(step): penup() forward(step) pendown()
def setupClock(radius): reset() pensize(7) for i in range(60): Skip(radius) if i % 5 == 0: forward(20) Skip(-radius - 20) else: dot(5) Skip(-radius) right(6)
def makeHand(name, length): reset() Skip(-0.1 * length) begin_poly() forward(1.1 * length) end_poly() handForm = get_poly() register_shape(name, handForm)
def init(): global secHand, minHand, hurHand, printer mode("logo") secHand = Turtle() makeHand("secHand", 125) secHand.shape("secHand") minHand = Turtle() makeHand("minHand", 130) minHand.shape("minHand") hurHand = Turtle() makeHand("hurHand", 90) hurHand.shape("hurHand") for hand in secHand, minHand, hurHand: hand.shapesize(1, 1, 3) hand.speed(0) printer = Turtle() printer.hideturtle() printer.penup()
def Week(t): week = ["星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期七"] return week[t.weekday()]
def Day(t): return "%s %d %d" % (t.year, t.month, t.day)
def Tick(): t = datetime.today() second = t.second + t.microsecond * 0.000001 minute = t.minute + t.second / 60.0 hour = t.hour + t.minute / 60.0 secHand.setheading(second * 6) minHand.setheading(minute * 6) hurHand.setheading(hour * 30) tracer(False) printer.fd(70) printer.write(Week(t), align="center", font=("Courier", 14, "bold")) printer.back(130) printer.write(Day(t), align="center", font=("Courier", 14, "bold")) printer.home() tracer(True) ontimer(Tick, 100)
def main(): tracer(False) init() setupClock(200) tracer(True) Tick() done()
main()
|