# ferry.py - tct - 5/19,20,21,24/15 import pygame, sys pygame.init() # slow ferry def sf(t): sp = t if sp >= 1760: srp = 3520-sp else: srp = sp return srp # fast ferry def ff(t): fp = 13./9.*t if fp <= 1760: frp = 1760-fp else: frp = fp-1760 return frp screen = pygame.display.set_mode([900,300]) # draw the ferries for t in range(2161): screen.fill([255, 255, 255]) inst1_font = pygame.font.Font(None, 24) str = "slow ferry : %.1f" % sf(t) inst1_surf = inst1_font.render(str, 1, (255, 0, 0)) screen.blit(inst1_surf, [100, 50]) str = "fast ferry : %.1f" % ff(t) inst1_surf = inst1_font.render(str, 1, (0, 0, 255)) screen.blit(inst1_surf, [660, 50]) str = "http://primepuzzle.com/tunxis/ferry.htm" inst1_surf = inst1_font.render(str, 1, (0, 0, 0)) screen.blit(inst1_surf, [330, 250]) pygame.draw.rect(screen, (255,0,0), (sf(t)/2,100,20,10), 2) pygame.draw.rect(screen, (0,0,255), (ff(t)/2,150,20,10), 2) pygame.display.flip() pygame.time.delay(10) while True: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit()