pygame-color-test/colors/main.py

36 lines
973 B
Python
Raw Normal View History

2023-02-19 14:19:43 -05:00
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()
2023-02-19 14:21:24 -05:00
window = pygame.display.set_mode((720, 720), pygame.FULLSCREEN)
2023-02-19 14:19:43 -05:00
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
2023-02-19 14:21:24 -05:00
if keyboard_event.type == pygame.KEYDOWN:
if keyboard_event.key == pygame.K_ESCAPE:
running = False
2023-02-19 14:19:43 -05:00
rainbow_pos %= 1530
window.fill(rainbow_spectrum(rainbow_pos))
rainbow_pos += 4
pygame.display.flip()
pygame.quit()