|
| 1 | + |
| 2 | + |
| 3 | + |
| 4 | +import pygame |
| 5 | +from math import sin, cos, pi |
| 6 | +from pymsgbox import alert |
| 7 | +WIDTH, HEIGHT = 800, 800 |
| 8 | +x0, y0 = WIDTH // 2, HEIGHT // 2 |
| 9 | + |
| 10 | +# Speed |
| 11 | +fps = 200 |
| 12 | +skip = 100 |
| 13 | + |
| 14 | + |
| 15 | +mod = 100 |
| 16 | +radius = x0 / 1.2 |
| 17 | +textRadius = x0 / 1.1 |
| 18 | +fontSize = 20 |
| 19 | +fontSize2 = int(1.5 * fontSize) |
| 20 | +res1, res2, res3, res4 = 0, 0, 0, 0 |
| 21 | +pointer = 50 |
| 22 | + |
| 23 | +pygame.init() |
| 24 | +screen = pygame.display.set_mode((WIDTH, HEIGHT)) |
| 25 | +clock = pygame.time.Clock() |
| 26 | +running = True |
| 27 | +font = pygame.font.Font(None, fontSize) |
| 28 | +font2 = pygame.font.Font(None, fontSize2) |
| 29 | + |
| 30 | + |
| 31 | + |
| 32 | +with open("input.txt", "r") as f: |
| 33 | + inp = f.readlines() |
| 34 | + |
| 35 | +for progress, row in enumerate(inp, 1): |
| 36 | + if not running: break |
| 37 | + row = row.strip() |
| 38 | + sens = 1 if row[0] == "R" else -1 |
| 39 | + turns = int(row[1:]) |
| 40 | + |
| 41 | + for i in range(turns): |
| 42 | + if not running: break |
| 43 | + pointer += sens |
| 44 | + pointer %= 100 |
| 45 | + res2 += pointer == 0 |
| 46 | + |
| 47 | + if i % skip != 0: continue |
| 48 | + |
| 49 | + |
| 50 | + for event in pygame.event.get(): |
| 51 | + if event.type == pygame.QUIT: |
| 52 | + running = False |
| 53 | + |
| 54 | + if event.type == pygame.KEYDOWN: |
| 55 | + if event.key == pygame.K_DOWN: |
| 56 | + fps = max(20, fps - 20) |
| 57 | + |
| 58 | + if event.key == pygame.K_UP: |
| 59 | + fps = min(500, fps + 20) |
| 60 | + |
| 61 | + if event.key == pygame.K_LEFT: |
| 62 | + skip = max(1, skip // 2) |
| 63 | + |
| 64 | + if event.key == pygame.K_RIGHT: |
| 65 | + skip = min(1000, skip * 2) |
| 66 | + |
| 67 | + |
| 68 | + screen.fill("white") |
| 69 | + pygame.draw.circle(screen, "black", (x0, y0), radius, 5) |
| 70 | + for n in range(mod): |
| 71 | + txt = font.render(str(n), True, "red") |
| 72 | + alpha = 2 * pi * n / mod - (pi / 2) |
| 73 | + x = textRadius * cos(alpha) |
| 74 | + y = textRadius * sin(alpha) |
| 75 | + screen.blit(txt, (x0 + x, y0 + y)) |
| 76 | + if n == pointer: |
| 77 | + pygame.draw.line(screen, "blue", (x0, y0), (x0 + x, y0 + y), 2) |
| 78 | + state = f"Fps: {fps}--Skip: {skip}--Instruction: {row}--res1: {res1}--res2: {res2}--Progress: {progress * 100 / len(inp): .2f} %" |
| 79 | + txt = font2.render(state, True, "green", "black") |
| 80 | + screen.blit(txt, (0, 0)) |
| 81 | + |
| 82 | + pygame.display.flip() |
| 83 | + clock.tick(fps) |
| 84 | + |
| 85 | + res1 += pointer == 0 |
| 86 | + |
| 87 | + |
| 88 | +alert(state) |
| 89 | +pygame.quit() |
| 90 | + |
0 commit comments