pygame is
Python
Simple DirectMedia Layer
 
 
pygame.org is
Site Swing
Wiki

RGBColorConversion

      
Search:  
 
 

Note: pygame 1.8.1 includes a Color class with many colorspace conversion routines: http://www.pygame.org/docs/ref/color.html

# Python comes with some color conversion methods.
import colorsys
 
# A typical color value using a 0xFF representation (e.g. pygame)
color = (255, 100, 100)
 
# Normalization method, so the colors are in the range [0, 1]
def normalize (color):
    return color[0] / 255.0, color[1] / 255.0, color[2] / 255.0
 
# Reformats a color tuple, that uses the range [0, 1] to a 0xFF
# representation.
def reformat (color):
    return int (round (color[0] * 255)), \
           int (round (color[1] * 255)), \
           int (round (color[2] * 255))
 
# Supported conversions. They require 3 arguments.
hls = colorsys.rgb_to_hls (*normalize (color))
hsv = colorsys.rgb_to_hsv (*normalize (color))
yiq = colorsys.rgb_to_yiq (*normalize (color))
 
# Reformat a HLS/HSV/YIQ color to a 0xFF RGB representation.
rgb1 = reformat (colorsys.hls_to_rgb (*hls))
rgb2 = reformat (colorsys.hsv_to_rgb (*hsv))
rgb3 = reformat (colorsys.yiq_to_rgb (*yiq))
spotlight

 
our projects
pygame.org welcomes all python game, art, music, sound, video and multimedia projects. If they use pygame or not.
 
recent releases
Nov 13, 2014

Nov 11, 2014


Nov 10, 2014

Nov 9, 2014

Nov 6, 2014


Nov 4, 2014

Nov 3, 2014

Oct 28, 2014

Oct 21, 2014

Oct 16, 2014

... more!
 
for pygame related questions, comments, and suggestions, please see help (lists, irc)