From da934a838305bab72bd12dcd2b83e689f7c1cc3f Mon Sep 17 00:00:00 2001 From: Jim Salem Date: Fri, 28 Jan 2011 18:28:25 -0500 Subject: 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) --- util/ColorOps.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'util') 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) -- cgit v1.2.3