diff options
author | Daniel <dmt@daniel-desktop.(none)> | 2011-01-29 18:54:50 -0800 |
---|---|---|
committer | Daniel <dmt@daniel-desktop.(none)> | 2011-01-29 18:54:50 -0800 |
commit | ff07b18748c64243c1c6bc62f489bfd03205d13a (patch) | |
tree | db95373a3511be0dd1e700a78e9f1ea7320769a4 /util/ColorOps.py | |
parent | 83931a3c8e65b4018e98b4986458d1df7172ab91 (diff) | |
parent | 277a5143165d2553ce5e97f151cc6b3cea426468 (diff) |
Merge branch 'master' of github.com:rcoh/SmootLight
Diffstat (limited to 'util/ColorOps.py')
-rw-r--r-- | util/ColorOps.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/util/ColorOps.py b/util/ColorOps.py index 037957a..4b1162a 100644 --- a/util/ColorOps.py +++ b/util/ColorOps.py @@ -1,4 +1,5 @@ import random +import colorsys from util.TimeOps import Stopwatch def randomColor(): return [random.randint(0,255) for i in range(3)] @@ -11,6 +12,8 @@ def safeColor(c): c[0] = c[0] if c[0] < 255 else 255 c[1] = c[1] if c[1] < 255 else 255 c[2] = c[2] if c[2] < 255 else 255 + + return c def combineColors(colors): @@ -23,3 +26,17 @@ def combineColors(colors): def multiplyColor(color, percent): return safeColor([channel*(percent) for channel in color]) + +def floatToIntColor(rgb): + rgb[0] = int(rgb[0]*256 + .5) + rgb[1] = int(rgb[1]*256 + .5) + rgb[2] = int(rgb[2]*256 + .5) + return safeColor(rgb) + +def randomBrightColor(): + hue = random.random() + sat = random.random()/2.0 + .5 + val = 1.0 + hue, sat, val = colorsys.hsv_to_rgb(hue, sat, val) + ret = [hue, sat, val] + return floatToIntColor(ret) |