-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.py
32 lines (26 loc) · 836 Bytes
/
utils.py
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
28
29
30
31
32
import Vector
import math
def CallIfExists(func,*args):
if type(func) is types.FunctionType or type(func) is types.MethodType:
return func(*args)
def remap(thing,lowerbound,newrange,oldrange):
return(((thing-lowerbound) * newrange) / oldrange)
def getGradCol(number,colors):
start = -99999999999999
end = 999999999999999
for found in colors.keys():
if found <= number:
if found > start:
start = found
else:
if found < end:
end = found
dist = end-start
pctage = remap(number,float(start),float(1),dist)
def lerp(a,b,t):
return a+(b-a)*t
endcol = (lerp(colors[start][0],colors[end][0],pctage),
lerp(colors[start][1],colors[end][1],pctage),
lerp(colors[start][2],colors[end][2],pctage),
lerp(colors[start][3],colors[end][3],pctage))
return endcol