toggling cells in matrices?

Oct 11, 2008 at 8:01pm

toggling cells in matrices?

hey all,

I have a series of 16×8 char matrices, and I would like to toggle cells
between two states, like an on/off thing.

Now, I had the idea of going through a jit.op @op % @val 255, but that’s
about as far as that train of thought took me.

Next I came up with the following – a loop going through a jit.op @op
fold @val 1, which does work – but that involves going from char to
float32, and, subsequently, back again. (patch attached)

Is there a simpler way? In max I’d accum->modulo 255, and I guess I’m
looking for that kind of functionality in Jitter, preferably without
doing [getcell], which seems quite cumbersome and slow.

Cheers, and I hope I made my question sensible….?
Andreas.

– Pasted Max Patch, click to expand. –
#40290
Oct 11, 2008 at 8:37pm

The char range is from [0, 255] so if you have a char matrix followed
by [jit.op @op % @val 255], the possible range of output values is
limited to [0, 254]. If you just want to toggle, you might want to
look at logical operations like &&, || etc. A simple toggle can be
implemented with [jit.op @op !]

wes

#142364
Oct 11, 2008 at 11:30pm

To selectively toggle specific cells in a char matrix, you can use [jit.op @op ^], otherwise known as XOR. In bitwise arithmetic, the XOR operator is used to toggle the state of specific bits using a bitmask. So, the @op ^ will toggle any cells that are white in the mask image, and not mess with the black ones.

Andrew B.

– Pasted Max Patch, click to expand. –
#142365
Oct 11, 2008 at 11:42pm

Wes and Andrew, thanks so much for sharing! :D

Andrew, I realized that even your super-slick example could be
simplified even more, so here is my final entry – this is going in the
patch more or less like this.
Please let me know if you have any further tweaks.

Cheers,
Andreas.

– Pasted Max Patch, click to expand. –
#142366
Oct 11, 2008 at 11:44pm

> To selectively toggle specific cells in a char matrix, you can use [jit.op @op ^], otherwise known as XOR. In bitwise arithmetic, the XOR operator is used to toggle the state of specific bits using a bitmask. So, the @op ^ will toggle any cells that are white in the mask image, and not mess with the black ones.

… yes, XOR is better than !. Follow ab’s advice on this one. sorry
’bout the brain spasm.
wes

#142367

You must be logged in to reply to this topic.