Filling a matrix randomly with preselected colors.

thruvik's icon

I would like to fill a matrix randomly with preselected colors.

Basically, I would like to have the jit.noise object, but rather than it spitting out complete randomness, I would like for it to choose its colors from a predetermined palette.

Working to achieve this I have tried to utilize a matrix for lookup values, using getcell and setcell to pick random cells from the lookup and insert them into the main matrix. However, this becomes quite heavy for the computer when it is done on larger images. I do not need a 30fps update rate on this, but it would be nice if it took less than 4 secs to compute for a single image.

I have my suspicions that it is possible to use jit.repos on a full scale version of the lookup table, or jit.charmap on a noise image, but I have not gotten this to work. I cannot find a good way to create random pixel placement in jit.repos, and jit.charmap does not produce a clean version of the image, using only the palette provided.

Hoping for some good tips!

Rob Ramirez's icon

if I understand you correctly, this is pretty easy to do with jit.gl.pix (or jit.pix if you prefer to stay in matrix land). here's a basic example (double click the gl.pix object to see how it's done):

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

thruvik's icon

That worked as intended! Seems like I need to learn gl and jit.pix for future reference. Thank you for your help!