bilinear interpolation of colors?

metamax's icon

This shouldn't be difficult but... :(

How do I create four-color gradient matrices of variable dimension with custom colors at each corner? I ideally I would like to use expressions to achieve this, though my understanding of jitter and jit.expr is limited.

At some point I would also like to apply curves to the gradients so I'm not limited to linear interpolation.. as well as selecting specific cells in the matrix as interpolation points (not just the corners).

Thoughts? This is kinda what I'm talking about...

Max Patch
Copy patch and select New From Clipboard in Max.

-

Floating Point's icon

I believe we have parallel lives--

Max Patch
Copy patch and select New From Clipboard in Max.

here is something I did a little while back:
save this as bilinear_interpolator

Max Patch
Copy patch and select New From Clipboard in Max.

then use this parent patch:

note the args are col, row dim for target matrix.

for some reason it kludges out on my machine if the dims are more than about 15*15-- something to do with using the uzis I suspect. Anyway I've since done a much more efficient jit.pix version which I can post if you want.

Christopher Dobrian's icon
Max Patch
Copy patch and select New From Clipboard in Max.

In jit.expr I think the main factors you'll want to consider are norm[] which gives you a value from 0 to 1 across a particular dimension, and in[] which gives you the value of the cells of the matrix coming in each inlet.

Floating Point's icon
Max Patch
Copy patch and select New From Clipboard in Max.

something I prepared earlier....

this is about twenty times slower than my previous method using lists with uzi.
the jit.gen method is another order of magnitude faster again.

Floating Point's icon
Max Patch
Copy patch and select New From Clipboard in Max.

and here is the most efficient using jit.gen

metamax's icon

You guys are awesome. I need to get my head around jit.expr.. particularly the in[] operator. I have been going in and out of matrices with spill and fill to combine jitter expressions into a single matrix... :/ Good to know that there's an easier way. :)

I'm still looking for more control of the gradients. I'll post some examples in a bit.

And thanks!