Package sparked :: Package graphics :: Module util
[hide private]
[frames] | no frames]

Source Code for Module sparked.graphics.util

 1  # Copyright (c) 2010 Arjan Scherpenisse 
 2  # See LICENSE for details. 
 3   
 4  """ 
 5  Utility functions for graphics. 
 6  """ 
 7   
8 -def parseColor(x):
9 """ 10 Given a string in hexadecimal RGB notation, return a (r,g,b) triplet where r,g,b in 0.0 >= x > 1.0 11 """ 12 if len(x) not in [3,4,6,7]: 13 return False 14 if x[0] == "#": 15 x = x[1:] 16 if len(x) == 3: 17 x = x[0]+x[0]+x[1]+x[1]+x[2]+x[2] 18 19 col = [] 20 for i in range(3): 21 col.append(int(x[i*2:i*2+2], 16)/255.) 22 return tuple(col)
23