Shuffle matrix cells - any ideas?

tom w's icon

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

Jesse's icon

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.

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

Basic technique in the below patcher.

tom w's icon

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

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

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

tom w's icon

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

tom w's icon

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 256x256.

Thanks again for the input

Tom

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