aboutsummaryrefslogtreecommitdiff
path: root/util/ColorOps.py
blob: e384605d7bcfb72cc8f4535673609641d33f7129 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import random
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:
        result[0] += c[0]
        result[1] += c[1]
        result[2] += c[2]
    return safeColor(result)

def multiplyColor(color, percent):
    return safeColor([channel*(percent) for channel in color])