Skip to content

Instantly share code, notes, and snippets.

@Eckankar
Last active October 19, 2020 09:27
Show Gist options
  • Save Eckankar/3a730a072107f4c882b56d445b465eed to your computer and use it in GitHub Desktop.
Save Eckankar/3a730a072107f4c882b56d445b465eed to your computer and use it in GitHub Desktop.
Rainbow colors in PyGame
#!/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