Last active
October 19, 2020 09:27
-
-
Save Eckankar/3a730a072107f4c882b56d445b465eed to your computer and use it in GitHub Desktop.
Rainbow colors in PyGame
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import pygame | |
pygame.init() | |
disp = pygame.display.set_mode((640, 480), pygame.DOUBLEBUF) | |
color_value = 0 | |
def rainbow_color(value): | |
step = (value // 256) % 6 | |
pos = value % 256 | |
if step == 0: | |
return (255, pos, 0) | |
if step == 1: | |
return (255-pos, 255, 0) | |
if step == 2: | |
return (0, 255, pos) | |
if step == 3: | |
return (0, 255-pos, 255) | |
if step == 4: | |
return (pos, 0, 255) | |
if step == 5: | |
return (255, 0, 255-pos) | |
running = True | |
while running: | |
for event in pygame.event.get(): | |
if event.type == pygame.QUIT: | |
running = False | |
disp.fill( rainbow_color(color_value) ) | |
pygame.display.flip() | |
color_value = (color_value + 1) % (256 * 6) | |
pygame.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment