()
| 50 | |
| 51 | |
| 52 | def main(): |
| 53 | bext.clear() |
| 54 | # Draw the circle of the clock: |
| 55 | for y, row in enumerate(CLOCKFACE.splitlines()): |
| 56 | for x, char in enumerate(row): |
| 57 | if char != ' ': |
| 58 | bext.goto(x, y) |
| 59 | print(char) |
| 60 | |
| 61 | while True: # Main program loop. |
| 62 | # Get the current time from the computer's clock: |
| 63 | currentTime = time.localtime() |
| 64 | h = currentTime.tm_hour % 12 # Use 12-hour clock, not 24. |
| 65 | m = currentTime.tm_min |
| 66 | s = currentTime.tm_sec |
| 67 | |
| 68 | # Draw the second hand: |
| 69 | secHandDirection = COMPLETE_ARC * (s / 60) + OFFSET_90_DEGREES |
| 70 | secHandXPos = math.cos(secHandDirection) |
| 71 | secHandYPos = math.sin(secHandDirection) |
| 72 | secHandX = int(secHandXPos * SECOND_HAND_LENGTH + CENTERX) |
| 73 | secHandY = int(secHandYPos * SECOND_HAND_LENGTH + CENTERY) |
| 74 | secHandPoints = line(CENTERX, CENTERY, secHandX, secHandY) |
| 75 | for x, y in secHandPoints: |
| 76 | bext.goto(x, y) |
| 77 | print(SECOND_HAND_CHAR, end='') |
| 78 | |
| 79 | # Draw the minute hand: |
| 80 | minHandDirection = COMPLETE_ARC * (m / 60) + OFFSET_90_DEGREES |
| 81 | minHandXPos = math.cos(minHandDirection) |
| 82 | minHandYPos = math.sin(minHandDirection) |
| 83 | minHandX = int(minHandXPos * MINUTE_HAND_LENGTH + CENTERX) |
| 84 | minHandY = int(minHandYPos * MINUTE_HAND_LENGTH + CENTERY) |
| 85 | minHandPoints = line(CENTERX, CENTERY, minHandX, minHandY) |
| 86 | for x, y in minHandPoints: |
| 87 | bext.goto(x, y) |
| 88 | print(MINUTE_HAND_CHAR, end='') |
| 89 | |
| 90 | # Draw the hour hand: |
| 91 | hourHandDirection = COMPLETE_ARC * (h / 12) + OFFSET_90_DEGREES |
| 92 | hourHandXPos = math.cos(hourHandDirection) |
| 93 | hourHandYPos = math.sin(hourHandDirection) |
| 94 | hourHandX = int(hourHandXPos * HOUR_HAND_LENGTH + CENTERX) |
| 95 | hourHandY = int(hourHandYPos * HOUR_HAND_LENGTH + CENTERY) |
| 96 | hourHandPoints = line(CENTERX, CENTERY, hourHandX, hourHandY) |
| 97 | for x, y in hourHandPoints: |
| 98 | bext.goto(x, y) |
| 99 | print(HOUR_HAND_CHAR, end='') |
| 100 | |
| 101 | sys.stdout.flush() # (Required for bext-using programs.) |
| 102 | |
| 103 | # Keep looping until the second changes: |
| 104 | while True: |
| 105 | time.sleep(0.01) |
| 106 | if time.localtime().tm_sec != currentTime.tm_sec: |
| 107 | break |
| 108 | |
| 109 | # Erase the clock hands: |
no test coverage detected