toggling cells in matrices?


    Oct 11 2008 | 8:01 pm
    hey all,
    I have a series of 16x8 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.

    • Oct 11 2008 | 8:37 pm
      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
    • Oct 11 2008 | 11:30 pm
      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.
    • Oct 11 2008 | 11:42 pm
      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.
    • Oct 11 2008 | 11:44 pm
      > 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