Activity Stream
93,241 MEMBERS
70 ONLINE
RGB Color Gradation Function RGB Color Gradation Function RGB Color Gradation Function RGB Color Gradation Function RGB Color Gradation Function
Results 1 to 1 of 1
  1.    Tweet this post   Share This Post On Facebook Share This Post On Google+
    #1
    Programmar
    Xcode's Avatar

    Star RGB Color Gradation Function

    This is a function that takes two normal HTML colors (for instance #CCCCCC; and #00FFFF and returns a specified number of color codes necessary to blend between them.

    Source Code : 
    import string
     

    [Login or Register to remove this advertisement]

    def make_color_tuple
    color ):
        
    """
        turn something like "
    #000000" into 0,0,0
        
    or "#FFFFFF into "255,255,255"
        """
        
    color[1:3]
        
    color[3:5]
        
    color[5:7]
     
        
    int(R16)
        
    int(G16)
        
    int(B16)
     
        return 
    R,G,B
     
    def interpolate_tuple
    startcolorgoalcolorsteps ):
        
    """
        Take two RGB color sets and mix them over a specified number of steps.  Return the list
        """
        
    # white
     
        
    startcolor[0]
        
    startcolor[1]
        
    startcolor[2]
     
        
    targetR goalcolor[0]
        
    targetG goalcolor[1]
        
    targetB goalcolor[2]
     
        
    DiffR targetR R
        DiffG 
    targetG G
        DiffB 
    targetB B
     
        buffer 
    = []
     
        for 
    i in range(0steps +1):
            
    iR + (DiffR steps)
            
    iG + (DiffG steps)
            
    iB + (DiffB steps)
     
            
    hR string.replace(hex(iR), "0x""")
            
    hG string.replace(hex(iG), "0x""")
            
    hB string.replace(hex(iB), "0x""")
     
            if 
    len(hR) == 1:
                
    hR "0" hR
            
    if len(hB) == 1:
                
    hB "0" hB
     
            
    if len(hG) == 1:
                
    hG "0" hG
     
            color 
    string.upper("#"+hR+hG+hB)
            
    buffer.append(color)
     
        return 
    buffer
     
    def interpolate
    startcolorgoalcolorsteps ):
        
    """
        wrapper for interpolate_tuple that accepts colors as html ("
    #CCCCC" and such)
        
    """
        start_tuple = make_color_tuple(startcolor)
        goal_tuple = make_color_tuple(goalcolor)
     
        return interpolate_tuple(start_tuple, goal_tuple, steps)
     
     
     
    def printchart(startcolor, endcolor, steps):
     
        colors = interpolate(startcolor, endcolor, steps)
     
        for color in colors:
            print color
     
     
    # Example... show us 16 values of gradation between these two colors
    printchart("
    #999933", "#6666FF", 16) 
    Xcode Reviewed by Xcode on . RGB Color Gradation Function This is a function that takes two normal HTML colors (for instance #CCCCCC; and #00FFFF;) and returns a specified number of color codes necessary to blend between them. import string def make_color_tuple( color ): """ turn something like "#000000" into 0,0,0 or "#FFFFFF into "255,255,255" """ R = color Rating: 5

  2. The Following 1 Users Say Thank You to Xcode For This Useful Post:
    [ Click to Expand ]

    Rebel (4th March 2012)

  3.   Advertisements

Thread Information

Users Browsing this Thread

There Are Currently 1 Users Browsing This Thread. (0 Members and 1 Guests)

Similar Threads

  1. Replies: 0
    Last Post: 14th February 2014, 11:09 PM
  2. explode function
    By Xcode in forum Objective C
    Replies: 0
    Last Post: 17th March 2013, 05:04 PM
  3. RGB Gradation Chart Generator
    By Xcode in forum Python
    Replies: 0
    Last Post: 3rd March 2012, 06:49 PM
  4. [FULL] Color ID LED Light Color Customizer for BBM™ - v2.0.8
    By Mobile_Guru in forum Blackberry Applications
    Replies: 0
    Last Post: 10th January 2012, 03:15 PM
  5. Scroll to top function
    By Xcode in forum JavaScript
    Replies: 0
    Last Post: 18th November 2011, 08:00 PM

Tags for this Thread

BE SOCIAL
RGB Color Gradation Function RGB Color Gradation Function RGB Color Gradation Function RGB Color Gradation Function RGB Color Gradation Function