making a matrix scroll the *other* direction

Sophia's icon

I recently learned the trick where one can make a jitter matrix seem to scroll to the right by offsetting the source and destination dimensions.

I'm wondering why this isn't reversible, in other words why making the dstdim range one value higher than the srcdim range seems to erase the matrix rather than making it scroll to the left.

Is there a way to make a jitter matrix scroll in both directions?

Andrew Benson's icon

You wanna try posting up a small patch that shows what you've got so far?

AB

vade's icon

Andrew, how do I get an icon on the forums?!

Sophia's icon

Here you go:

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

Ben Bracken's icon

huh, interesting patch! Might be some different approaches that would work better, depending on your end goal, but with your current configuration, you can just flip 'er around:

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

Sophia's icon

I'm a little confused. Doesn't this work exactly the same as the patch I posted?

Ben Bracken's icon

whoops, posted wrong patch. i've updated the previous post.

-Ben

Sophia's icon

Interesting, I never thought of just flipping it around like that. This works for what I need, but I still want to know why my way didn't. I don't understand it.

Sophia's icon

On second thought, I'm not sure this solution would work for my patch as I wanted to be able to toggle between scrolling both directions so I can center the data in the pwindow. Back to the beginning...

Sophia's icon

Any more ideas?

Andrew Benson's icon
Max Patch
Copy patch and select New From Clipboard in Max.

jit.convolve can also be used for shift-register style scrolling. Just change which pixel of the kernel is set to 1. to switch scrolling direction.

Sophia's icon

Thanks Andrew! This should do everything I need. And good guess as to its use: a shift register.

I only barely understand how this works and still don't understand why my original example doesn't, but perhaps I should let it go unless anyone wants to offer an explanation.

Bill Mauchly's icon

(Sorry, a little late to the party...)

I think I see what was wrong with original coding.
The matrix was being copied onto itself. That is an okay thing to do, unless you are overwriting data in the matrix that has not been copied yet.

So apparently Max first copies location 1 into location 0...
0
1
etc
and that works for the shift left.

But for the shift right, the original data in location 1 is destroyed by the copy, for it now contains the data from 0, so that data is replicated throughout the matrix.
1
2
3

So the solution is to use an extra data copy, a second matrix.

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

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

You could use the 'offset_x' attribute of jit.rota.

Bill Mauchly's icon

Nice. That is definitely the most elegant way to do it.

I think I looked briefly at jit.rota, but got scared away by the apparent complexity of the underlying operations. (Cosines and such for each x,y new location, according to the formula on the help page.) I have an underlying aversion, maybe a phobia, about code that is not at least reasonably efficient. Of course, particularly on modern machines, I'm being silly.

Asher's icon

Hey everyone, does anyone know how to make @andrew benson's Jit.convolve method wrap? Thanks

Asher's icon

sorry, let me expand a bit. I'm having trouble replacing the jit.noise with a regular matrix that i can load an image into. I can load an image into the jit.matrix "shift" but then the image doesn't wrap when it scrolls through. Any help would be appreciated, thanks.