aboutsummaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorGravatar Jim Salem <jsalem@gmail.com>2011-01-28 18:28:25 -0500
committerGravatar suny@mit.edu <necsys@necsys-susanne-ubuntu-2.(none)>2011-01-28 18:31:08 -0500
commitda934a838305bab72bd12dcd2b83e689f7c1cc3f (patch)
tree1295c5ba609d7e04ac1fa1173ee2187f7cfb8d55 /util
parenta7d6577e55ebd665ad9e4f45183836f11b3c6fd4 (diff)
New Flasher behavior which fades colors in and out.
Several new color functions. Created a "firefly" demo (moving colored bubbles that fade in and out)
Diffstat (limited to 'util')
-rw-r--r--util/ColorOps.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/util/ColorOps.py b/util/ColorOps.py
index 037957a..d971ad0 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)]
@@ -23,3 +24,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)