Skip to content

Instantly share code, notes, and snippets.

@wkta
Created March 22, 2014 11:22
Show Gist options
  • Save wkta/9705514 to your computer and use it in GitHub Desktop.
Save wkta/9705514 to your computer and use it in GitHub Desktop.
#MonthOfCode day 15 - yellow
import pygame
from pygame.locals import *
import sys
from time import sleep
# init. pygame libr; create the screen and diplays a help message in the console
pygame.init()
DISPLAYSURF = pygame.display.set_mode((640, 480))
src_color = pygame.Color('antiquewhite3')
targ_color = pygame.Color('yellow')
#draw it to the screen
pygame.display.set_caption('from white to yellow!')
interp_value=0.0
while interp_value<=1.0: # main game loop
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
src_triplet =( src_color.r, src_color.g, src_color.b )
targ_triplet =( targ_color.r, targ_color.g, targ_color.b )
interp_value +=0.01
interp_triplet = map(
lambda a,b: int( (1.0-interp_value) * a + interp_value* b ),
src_triplet,
targ_triplet )
current_color = pygame.Color( *interp_triplet)
sleep(0.1 )
DISPLAYSURF.fill( current_color )
pygame.display.update() #Q: whats the difference between update n flip?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment