## Python matrix to TOP

### Python matrix to TOP

Hey, I'am beginner

I generate matrix with a python script like :
[[10011]
[01101]
[10000]
[22302]
[44444]]

(The matrix will be animated in a second time)

I would like generate a image from this matrix
Where for exemple :
0 is white
1 is red
2 is yellow
3 is bleu
4 is green

What will be the process to do this work ?
- DAT(table) to CHOP to TOP ?
- Maybe directly in python with the opposite way of sample, like set value (r,g,b,a) of each pixel ?
Attachments
DEST.png (16.16 KiB) Viewed 1098 times
jeffazzo

Posts: 6
Joined: Wed Sep 12, 2018 1:22 pm

### Re: python DAT to TOP

Hey there,

If you want to do this using the matrix you have written down, you will need to create a color coding for each number. Most comfortable ways is to use a Python dictionary for the conversion. Further on, you can create tables with rgb values for each pixel row, and use a DatTo chop to convert the channels furtherinto TOPs. Find an example attached with a possible approach using just python and standard TD objects.

Best,
Darien

PS: I noticed that with this approach colors were at first inverted, didn't pay much attention to the order , so you need to evaluate the matrix in reverse order to have it as in your example, that's why this line of code, in case you wonder:
Code: Select all
`for i, m in enumerate(reversed(matrix), 1):`
Attachments
MatrixToColor.tox
Conversion to texture from matrix
__________
Darien Brito | AV artist - Multimedia Programmer
Qvoloid

Posts: 75
Joined: Wed Jun 25, 2014 6:29 pm
Location: Netherlands, Den Haag

### Re: Python matrix to TOP

Really, thank you

I will study all that
jeffazzo

Posts: 6
Joined: Wed Sep 12, 2018 1:22 pm

### Re: Python matrix to TOP

hey

Everything works very well.

What will be the best way, if the size of my matrix is ​​[128,128]?
I can manually duplicate the nodes "conversion [x]" from 1 to 128.
But for my curiosity, with matices of [1024,1024], (TD will be very slow), but how?

best,
Jeff
jeffazzo

Posts: 6
Joined: Wed Sep 12, 2018 1:22 pm

### Re: Python matrix to TOP

HI Jeff,

Yes, the first example I sent will not scale up to very large sizes. It was meant to illustrate how you could tackle this issue. If you understand the principle in that first example, then the generalized solution with that approach would not be hard to infer. Find attached a generalized solution. Change the "n" variable in the controls panel and click "Generate" to generate a table of n by n dimensions i.e (1024x1024). I'm using random data but you can just plug your data there.

Best,
Darien
Attachments
MatrixToColorGeneralized.tox
Generalized solution
__________
Darien Brito | AV artist - Multimedia Programmer
Qvoloid

Posts: 75
Joined: Wed Jun 25, 2014 6:29 pm
Location: Netherlands, Den Haag

### Re: Python matrix to TOP

Hi Darien,
So light and extremely effective.
jeffazzo

Posts: 6
Joined: Wed Sep 12, 2018 1:22 pm