33 lines
806 B
Python
33 lines
806 B
Python
import pygame
|
|
|
|
|
|
def rainbow_spectrum(position):
|
|
relative_pos = position % 1530
|
|
red = max(0, min(255, 510 - relative_pos), min(255, relative_pos - 1020))
|
|
green = max(0, min(255, relative_pos, 1020 - relative_pos))
|
|
blue = max(0, min(255, relative_pos - 510, 1530 - relative_pos))
|
|
return red, green, blue
|
|
|
|
|
|
def main():
|
|
pygame.init()
|
|
clock = pygame.time.Clock()
|
|
window = pygame.display.set_mode((720, 720))
|
|
rainbow_pos = 0
|
|
|
|
running = True
|
|
while running:
|
|
clock.tick(60)
|
|
|
|
for keyboard_event in pygame.event.get():
|
|
if keyboard_event.type == pygame.QUIT:
|
|
running = False
|
|
|
|
rainbow_pos %= 1530
|
|
window.fill(rainbow_spectrum(rainbow_pos))
|
|
rainbow_pos += 4
|
|
|
|
pygame.display.flip()
|
|
|
|
pygame.quit()
|