aboutsummaryrefslogtreecommitdiff
path: root/util/ColorOps.py
blob: 9da27fb9efe9e69a42905a613162eda4b528d3c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import random
from util.TimeOps import Stopwatch
def randomColor():
    return [random.randint(0,255) for i in range(3)]
def chooseRandomColor(colorList):
    return random.choice(colorList)
def safeColor(c):
    return [min(channel,255) for channel in c]
def combineColors(c1,c2):
    return safeColor([c1[i]+c2[i] for i in range(min(len(c1),len(c2)))])
def multiplyColor(color, percent):
    return safeColor([fastMultiply(channel, percent, 1) for channel in color])

def fastMultiply(value, mult, acc):
    if type(mult) == type(int(5)):
        return value*mult
    return int(value)*int(mult*10**acc)*10**(-acc)