aboutsummaryrefslogtreecommitdiff
path: root/util/ColorOps.py
diff options
context:
space:
mode:
Diffstat (limited to 'util/ColorOps.py')
-rw-r--r--util/ColorOps.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/util/ColorOps.py b/util/ColorOps.py
index 143444f..4b1162a 100644
--- a/util/ColorOps.py
+++ b/util/ColorOps.py
@@ -1,14 +1,21 @@
import random
+import colorsys
from util.TimeOps import Stopwatch
def randomColor():
return [random.randint(0,255) for i in range(3)]
+
def chooseRandomColor(colorList):
+ """Given a list of colors, pick one at random"""
return random.choice(colorList)
def safeColor(c):
+ """Ensures that a color is valid"""
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):
result = [0,0,0]
for c in colors:
@@ -16,5 +23,20 @@ def combineColors(colors):
result[1] += c[1]
result[2] += c[2]
return safeColor(result)
+
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)