Eli Fulkerson .com HomeProjectsColortest-gradation
 

RGB Gradation Chart Generator

Description:

I wrote this to better understand the relationship between RGB colors. Running it will generate a fairly large HTML file with all sorts of color transitions on it so you can see what is happening as colors are tweaked in different ways.

Platform:

  • no platform specific code, should work anywhere that has Python
  • Language:

  • Python
  • License:

  • I am placing this code (explicitly the file colortest-gradation.py.txt on this website) into the public domain. If you find it useful, I'd like to hear from you. If you build it into a larger application I would appreciate compensation and attribution, but am not requiring either.
  • Code:

    import string
    
    colors = ("00", "33", "66", "99", "CC", "FF")
    masks = ("#00~00", "#~~00", "#~0000", "#~00~", "#0000~", "#00~~", "#FF~00", "#~~~")
    
    
    f = open("colortest-gradation.html", 'w')
    f.write("<html><head><title>RGB Gradation</title></head><body bgcolor='black'><tt><b>")
    
    f.write("<p><font color='white'>Gentle gradations through RGB color:</font></p>\n")
    
    bytes = ("00", "11", "22", "33", "44", "55", "66", "77", "88", "99", "AA", "BB", "CC", "DD", "EE", "FF")
    halfbytes = ("00", "00", "11", "11", "22", "22", "33", "33", "44", "44", "55", "55", "66", "66", "77", "77")
    
    for green in bytes:
        f.write( "<li>" )
        for white in bytes:
            c1 = "#" + white + green + white
            c2 = "#" + white + white + green
            c3 = "#" + green + white + white
    
            f.write( "<font color='" + c1 + "'>" )
            f.write( "T")
            f.write( "</font>")
    
        for white in bytes:
            c1 = "#" + white + green + white
            c2 = "#" + white + white + green
            c3 = "#" + green + white + white
    
            f.write( "<font color='" + c2 + "'>" )
            f.write( "T")
            f.write( "</font>")
    
        for white in bytes:
            c1 = "#" + white + green + white
            c2 = "#" + white + white + green
            c3 = "#" + green + white + white
    
    
    
            f.write( "<font color='" + c3 + "'>" )
            f.write( "T")
            f.write( "</font>")
    
        f.write( "</li>\n" )
    
    f.write("<p><font color='white'>Double all bytes to get real color (#0A0 --> #00AA00 etc)</font></p>\n")
    
    f.write("<p><font color='white'>Green varied alone, Red/Blue varied together:</font></p>\n")
    for green in bytes:
        f.write( "<li>" )
        for white in bytes:
            c1 = "#" + white + green + white
            c2 = "#" + white + white + green
            c3 = "#" + green + white + white
    
            cout = "#" + c1[1] + c1[3] + c1[5] + " "
    
            f.write( "<font color='" + c1 + "'>" )
            f.write( cout)
            f.write( "</font>")
    
        f.write( "</li>\n" )
    
    f.write("<p><font color='white'>Blue varied alone, Red/Green varied together:</font></p>\n")
    for green in bytes:
    
        f.write( "<li>" )
        for white in bytes:
            c1 = "#" + white + green + white
            c2 = "#" + white + white + green
            c3 = "#" + green + white + white
    
            cout = "#" + c2[1] + c2[3] + c2[5] + " "
    
            f.write( "<font color='" + c2 + "'>" )
            f.write( cout)
            f.write( "</font>")
    
        f.write( "</li>\n" )
    
    f.write("<p><font color='white'>Red varied alone, Green/Blue varied together:</font></p>\n")
    for green in bytes:
        f.write( "<li>" )
        for white in bytes:
            c1 = "#" + white + green + white
            c2 = "#" + white + white + green
            c3 = "#" + green + white + white
    
            cout = "#" + c3[1] + c3[3] + c3[5] + " "
    
            f.write( "<font color='" + c3 + "'>" )
            f.write( cout)
            f.write( "</font>")
    
    
    
    
        f.write( "</li>\n" )
    
    for red in bytes:
        f.write("<p><font color='white'>Red locked at " + red + ", other colors varied:</font></p>\n")
        for green in halfbytes:
            f.write( "<li>\n")
            for blue in halfbytes:
                c3 = "#" + red + green + "00"
    
                cout = "#" + c3[1] + c3[3] + c3[5] + " "
    
                f.write( "<font color='" + c3 + "'>" )
                f.write( cout)
                f.write( "</font>")
    
    
    
    
            f.write( "</li>\n" )
    
    
    for green in bytes:
        f.write("<p><font color='white'>Green locked at " + green + ", other colors varied:</font></p>\n")
        for red in bytes:
            f.write( "<li>\n")
            for blue in bytes:
                c3 = "#" + red + green + blue
    
                cout = "#" + c3[1] + c3[3] + c3[5] + " "
    
                f.write( "<font color='" + c3 + "'>" )
                f.write( cout)
                f.write( "</font>")
    
    
    
    
            f.write( "</li>\n" )
    
    for blue in bytes:
        f.write("<p><font color='white'>Blue locked at " + blue + ", other colors varied:</font></p>\n")
        for green in bytes:
            f.write( "<li>\n")
            for red in bytes:
                c3 = "#" + red + green + blue
    
                cout = "#" + c3[1] + c3[3] + c3[5] + " "
    
                f.write( "<font color='" + c3 + "'>" )
                f.write( cout)
                f.write( "</font>")
    
    
    
    
            f.write( "</li>\n" )
    
    
    f.write("</b></tt></body></html>")
    f.close()

    Source code without formatting