loading txt information in a 2d array form?

Nov 25, 2011 at 12:27pm

loading txt information in a 2d array form?

HI all, i’m trying to load the information for a simple maze architecture from a text file. The text file is in the form
010
101
001
where “0″ are empty blocks (streets) and “1″ are building blocks.
What is the best way to do that? then i have to access it to build a jitter GL plan of it for exploration. I used a text object but it’s not so easy. Maybe there is a matrix text loader or something. Any suggestion on how to proceed?
A

#60247
Nov 25, 2011 at 3:39pm

Break apart any line like
010
into
0 1 0
by using [iter].
Then you have rows of 0 or 1 values, which you can load into a [jit.matrix] by using [jit.fill] per line.

Or, try and load the whole file into a matrix at once using [jit.textfile]. When I tried it, the matrix was ASCII characters: so 010 became 48 49 48. That could be used the same as 0 1 0 but you’d just need a different [sel] at the point you’re using it: [sel 48 49] versus [sel 0 1]. Either way, you can then tell [jit.sketch] to make a building or not :)

#216861
Nov 25, 2011 at 4:37pm

I think you want jit.textfile.

Test the patch below on a textmaze.txt file such as this:
10010011
00011001
10101110
01101011
11010101
10010001
00011101
10101110

– Pasted Max Patch, click to expand. –
#216862
Nov 25, 2011 at 9:25pm

Thanx guys, it’s exactly what i needed.
A

#216863

You must be logged in to reply to this topic.