|
| 1 | +# https://www.facebook.com/mayankgbrc/posts/2726954114288546 |
| 2 | +# Subscribed by Code House |
| 3 | +from turtle import * |
| 4 | +from datetime import datetime |
| 5 | + |
| 6 | +def jump(distanz, winkel=0): |
| 7 | + penup() |
| 8 | + right(winkel) |
| 9 | + forward(distanz) |
| 10 | + left(winkel) |
| 11 | + pendown() |
| 12 | + |
| 13 | +def hand(laenge, spitze): |
| 14 | + fd(laenge*1.15) |
| 15 | + rt(90) |
| 16 | + fd(spitze/2.0) |
| 17 | + lt(120) |
| 18 | + fd(spitze) |
| 19 | + lt(120) |
| 20 | + fd(spitze) |
| 21 | + lt(120) |
| 22 | + fd(spitze/2.0) |
| 23 | + |
| 24 | +def make_hand_shape(name, laenge, spitze): |
| 25 | + reset() |
| 26 | + jump(-laenge*0.15) |
| 27 | + begin_poly() |
| 28 | + hand(laenge, spitze) |
| 29 | + end_poly() |
| 30 | + hand_form = get_poly() |
| 31 | + register_shape(name, hand_form) |
| 32 | + |
| 33 | +def clockface(radius): |
| 34 | + reset() |
| 35 | + pensize(7) |
| 36 | + for i in range(60): |
| 37 | + jump(radius) |
| 38 | + if i % 5 == 0: |
| 39 | + fd(25) |
| 40 | + jump(-radius-25) |
| 41 | + else: |
| 42 | + dot(3) |
| 43 | + jump(-radius) |
| 44 | + rt(6) |
| 45 | + |
| 46 | +def setup(): |
| 47 | + global second_hand, minute_hand, hour_hand, writer |
| 48 | + mode("logo") |
| 49 | + make_hand_shape("second_hand", 125, 25) |
| 50 | + make_hand_shape("minute_hand", 130, 25) |
| 51 | + make_hand_shape("hour_hand", 90, 25) |
| 52 | + clockface(160) |
| 53 | + second_hand = Turtle() |
| 54 | + second_hand.shape("second_hand") |
| 55 | + second_hand.color("gray20", "gray80") |
| 56 | + minute_hand = Turtle() |
| 57 | + minute_hand.shape("minute_hand") |
| 58 | + minute_hand.color("blue1", "red1") |
| 59 | + hour_hand = Turtle() |
| 60 | + hour_hand.shape("hour_hand") |
| 61 | + hour_hand.color("blue3", "red3") |
| 62 | + for hand in second_hand, minute_hand, hour_hand: |
| 63 | + hand.resizemode("user") |
| 64 | + hand.shapesize(1, 1, 3) |
| 65 | + hand.speed(0) |
| 66 | + ht() |
| 67 | + writer = Turtle() |
| 68 | + #writer.mode("logo") |
| 69 | + writer.ht() |
| 70 | + writer.pu() |
| 71 | + writer.bk(85) |
| 72 | + |
| 73 | +def wochentag(t): |
| 74 | + wochentag = ["Monday", "Tuesday", "Wednesday", |
| 75 | + "Thursday", "Friday", "Saturday", "Sunday"] |
| 76 | + return wochentag[t.weekday()] |
| 77 | + |
| 78 | +def datum(z): |
| 79 | + monat = ["Jan.", "Feb.", "Mar.", "Apr.", "May", "June", |
| 80 | + "July", "Aug.", "Sep.", "Oct.", "Nov.", "Dec."] |
| 81 | + j = z.year |
| 82 | + m = monat[z.month - 1] |
| 83 | + t = z.day |
| 84 | + return "%s %d %d" % (m, t, j) |
| 85 | + |
| 86 | +def tick(): |
| 87 | + t = datetime.today() |
| 88 | + sekunde = t.second + t.microsecond*0.000001 |
| 89 | + minute = t.minute + sekunde/60.0 |
| 90 | + stunde = t.hour + minute/60.0 |
| 91 | + try: |
| 92 | + tracer(False) # Terminator can occur here |
| 93 | + writer.clear() |
| 94 | + writer.home() |
| 95 | + writer.forward(65) |
| 96 | + writer.write(wochentag(t), |
| 97 | + align="center", font=("Courier", 14, "bold")) |
| 98 | + writer.back(150) |
| 99 | + writer.write(datum(t), |
| 100 | + align="center", font=("Courier", 14, "bold")) |
| 101 | + writer.forward(85) |
| 102 | + tracer(True) |
| 103 | + second_hand.setheading(6*sekunde) # or here |
| 104 | + minute_hand.setheading(6*minute) |
| 105 | + hour_hand.setheading(30*stunde) |
| 106 | + tracer(True) |
| 107 | + ontimer(tick, 100) |
| 108 | + except Terminator: |
| 109 | + pass # turtledemo user pressed STOP |
| 110 | + |
| 111 | +def main(): |
| 112 | + tracer(False) |
| 113 | + setup() |
| 114 | + tracer(True) |
| 115 | + tick() |
| 116 | + return "EVENTLOOP" |
| 117 | + |
| 118 | +if __name__ == "__main__": |
| 119 | + mode("logo") |
| 120 | + msg = main() |
| 121 | + print(msg) |
| 122 | + mainloop() |
| 123 | + |
0 commit comments