Forums > MaxMSP

Shuffle matrix cells – any ideas?

January 2, 2014 | 5:30 am

Happy New Year

I’m trying to work out how I can shuffle the cells in a 2-dimensional matrix of arbitrary size: essentially, the effect I want to achieve is much like a jit.repos with a noise input, but I need to be sure that every individual cell in the input matrix is present in the output matrix, just in a different location.

I’m sure that such a thing should be possible, perhaps by iteratively selecting pairs of cells from a list and swapping their positions via jit.repos, but this seems awkward and slow. Any hints from people who have achieved such a thing in the past would be greatly appreciated.

Thanks

Tom


January 2, 2014 | 8:45 am

Try using urn to generate your repos coordinates. If your input matrix is larger than 256 elements (the list length limit) you can use multiple urn objects and concatenate the results with an appropriate offset.

Basic technique in the below patcher.

<code>

– Pasted Max Patch, click to expand. –

</code>


January 7, 2014 | 1:33 am

Thanks Jesse,

That’s a very elegant solution. I’m still hunting for something that will allow me to do this with much larger matrices though – with dims of at least 200 x 200. Perhaps this is only something achievable with a custom external, which is beyond my capabilities.

Tom


January 7, 2014 | 3:33 am

this will allow up to 256 * 256 using 2 urns: one for the x dim and one for the y, so each cell is guaranteed to be uniquely mapped. this example is 50*50, but it doesn’t have to be square

<code>

– Pasted Max Patch, click to expand. –

</code>


January 7, 2014 | 3:48 am

Thanks Floating Point, I’d begun to go down this route just now but you got there before me.

This will work perfectly for my current application, and I’ll continue to think about how to do this on an arbitrary sized matrix in the meantime.

Cheers

Tom


January 8, 2014 | 7:43 am

Hello all

Just in case it’s useful to anybody else, I’ve tinkered with the patches and added an additional level of scrambling to generate a more seemingly ‘random’ shuffling of cells. This patch still has a matrix dimension limit of 256×256.

Thanks again for the input

Tom

– Pasted Max Patch, click to expand. –

Viewing 6 posts - 1 through 6 (of 6 total)