blob: c4a081d287c10435bd51ae30f7180f75d5aa22d9 (
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
28
29
30
31
32
33
34
35
36
|
###
interpolates between a set of colors uzing a bezier spline
###
bezier = (colors) ->
colors = (chroma(c) for c in colors)
if colors.length == 2
# linear interpolation
[lab0, lab1] = (c.lab() for c in colors)
I = (t) ->
lab = (lab0[i] + t * (lab1[i] - lab0[i]) for i in [0..2])
chroma.lab lab...
else if colors.length == 3
# quadratic bezier interpolation
[lab0, lab1, lab2] = (c.lab() for c in colors)
I = (t) ->
lab = ((1-t)*(1-t) * lab0[i] + 2 * (1-t) * t * lab1[i] + t * t * lab2[i] for i in [0..2])
chroma.lab lab...
else if colors.length == 4
# cubic bezier interpolation
[lab0, lab1, lab2, lab3] = (c.lab() for c in colors)
I = (t) ->
lab = ((1-t)*(1-t)*(1-t) * lab0[i] + 3 * (1-t) * (1-t) * t * lab1[i] + 3 * (1-t) * t * t * lab2[i] + t*t*t * lab3[i] for i in [0..2])
chroma.lab lab...
else if colors.length == 5
I0 = bezier colors[0..2]
I1 = bezier colors[2..4]
I = (t) ->
if t < 0.5
I0 t*2
else
I1 (t-0.5)*2
I
chroma.interpolate.bezier = bezier
|