From cff537373ecc8543456a0de9f953c939fea9a5ce Mon Sep 17 00:00:00 2001 From: nickedyer Date: Sun, 19 Feb 2023 14:19:43 -0500 Subject: [PATCH] made screen change colors --- colors/__init__.py | 1 + colors/__main__.py | 5 +++++ colors/main.py | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 colors/__init__.py create mode 100644 colors/__main__.py create mode 100644 colors/main.py diff --git a/colors/__init__.py b/colors/__init__.py new file mode 100644 index 0000000..b8023d8 --- /dev/null +++ b/colors/__init__.py @@ -0,0 +1 @@ +__version__ = '0.0.1' diff --git a/colors/__main__.py b/colors/__main__.py new file mode 100644 index 0000000..41084f3 --- /dev/null +++ b/colors/__main__.py @@ -0,0 +1,5 @@ +import colors.main + +if __name__ == '__main__': + colors.main.main() + exit() \ No newline at end of file diff --git a/colors/main.py b/colors/main.py new file mode 100644 index 0000000..6b14088 --- /dev/null +++ b/colors/main.py @@ -0,0 +1,32 @@ +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()