Hello pd happy people, one question , i have a txt file with rgb colors . The txt file i have is something like this:
142 250 0 0 100 50 14 123 0 123 222 111 .... and so on.
each line represents the rgb color where the first item in each line is red , the second green and the third blue.
My question is this: i have a gem patch that creates random 3d shapes using nested repeat objects with geos. How can i read each line of my txt file (each color ) and apply to each repeated geo? for example if i have a sphere repeated 10 times, i would like that the first sphere would be the color of the first line in my txt file, the second sphere the second line in my txt file , the third sphere the third color in my txt file and so on.....
how can i do something like this????????????
any advice would be apreciatted !!
many thanks
pun.
punchik punchik wrote:
Hello pd happy people, one question , i have a txt file with rgb colors . The txt file i have is something like this:
142 250 0 0 100 50 14 123 0 123 222 111 .... and so on.
each line represents the rgb color where the first item in each line is red , the second green and the third blue.
My question is this: i have a gem patch that creates random 3d shapes using nested repeat objects with geos. How can i read each line of my txt file (each color ) and apply to each repeated geo? for example if i have a sphere repeated 10 times, i would like that the first sphere would be the color of the first line in my txt file, the second sphere the second line in my txt file , the third sphere the third color in my txt file and so on.....
how can i do something like this????????????
something like the attached?
but you probably really should use tables/arrays to store the values rather than using [textfile]
fgmasdr IOhannes
1 1 1 1 0 0 0 1 0 0 0 1 1 1 0 1 0 1 0 1 1
#N canvas 142 81 784 483 10; #X obj 135 138 gemhead; #X obj 547 125 gemwin; #X msg 548 96 create , 1; #X obj 135 195 repeat 10; #X obj 270 241 textfile; #X obj 135 166 t a b; #X msg 248 156 rewind; #X obj 135 299 color; #X obj 135 244 t a b; #X obj 135 350 translateXYZ 0.5 0 0; #X obj 135 326 sphere 0.1; #X obj 135 374 rotateXYZ 0 0 10; #X msg 327 165 read colors.txt cr; #X msg 341 304 rewind , bang; #X obj 341 284 spigot; #X obj 455 199 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0 1; #X obj 273 209 spigot 1; #X obj 339 220 == 0; #X obj 409 220 t f f; #X text 477 197 --> turn on to loop through the file; #X floatatom 281 93 5 0 0 0 - - -; #X obj 135 398 scale 0.9; #X connect 0 0 5 0; #X connect 2 0 1 0; #X connect 3 0 8 0; #X connect 4 0 7 1; #X connect 4 1 14 0; #X connect 5 0 3 0; #X connect 5 1 6 0; #X connect 6 0 16 0; #X connect 7 0 10 0; #X connect 8 0 7 0; #X connect 8 1 4 0; #X connect 9 0 11 0; #X connect 10 0 9 0; #X connect 11 0 21 0; #X connect 12 0 4 0; #X connect 13 0 4 0; #X connect 14 0 13 0; #X connect 15 0 18 0; #X connect 16 0 4 0; #X connect 17 0 16 1; #X connect 18 0 17 0; #X connect 18 1 14 1; #X connect 20 0 3 1;
yes, something like that thanks, but why should i use arrays instead text files? is it faster?
pun.
--- On Tue, 1/20/09, IOhannes m zmoelnig zmoelnig@iem.at wrote:
From: IOhannes m zmoelnig zmoelnig@iem.at Subject: Re: [PD] reading colors from txt file with repeat To: punchikk@yahoo.com Cc: pd-list@iem.at Date: Tuesday, January 20, 2009, 1:46 PM punchik punchik wrote:
Hello pd happy people, one question , i have a txt
file with rgb colors .
The txt file i have is something like this:
142 250 0 0 100 50 14 123 0 123 222 111 .... and so on.
each line represents the rgb color where the first
item in each line is red , the second green and the third blue.
My question is this: i have a gem patch that creates
random 3d shapes using nested repeat objects with geos.
How can i read each line of my txt file (each color ) and apply to each repeated geo? for example if i have a sphere repeated 10 times, i would like that the first sphere would be the color of the first line in my txt file, the second sphere the second line in my txt file , the third sphere the third color in my txt file and so on.....how can i do something like this????????????
something like the attached?
but you probably really should use tables/arrays to store the values rather than using [textfile]
fgmasdr IOhannes 1 1 1 1 0 0 0 1 0 0 0 1 1 1 0 1 0 1 0 1 1 #N canvas 142 81 784 483 10; #X obj 135 138 gemhead; #X obj 547 125 gemwin; #X msg 548 96 create , 1; #X obj 135 195 repeat 10; #X obj 270 241 textfile; #X obj 135 166 t a b; #X msg 248 156 rewind; #X obj 135 299 color; #X obj 135 244 t a b; #X obj 135 350 translateXYZ 0.5 0 0; #X obj 135 326 sphere 0.1; #X obj 135 374 rotateXYZ 0 0 10; #X msg 327 165 read colors.txt cr; #X msg 341 304 rewind , bang; #X obj 341 284 spigot; #X obj 455 199 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0 1; #X obj 273 209 spigot 1; #X obj 339 220 == 0; #X obj 409 220 t f f; #X text 477 197 --> turn on to loop through the file; #X floatatom 281 93 5 0 0 0 - - -; #X obj 135 398 scale 0.9; #X connect 0 0 5 0; #X connect 2 0 1 0; #X connect 3 0 8 0; #X connect 4 0 7 1; #X connect 4 1 14 0; #X connect 5 0 3 0; #X connect 5 1 6 0; #X connect 6 0 16 0; #X connect 7 0 10 0; #X connect 8 0 7 0; #X connect 8 1 4 0; #X connect 9 0 11 0; #X connect 10 0 9 0; #X connect 11 0 21 0; #X connect 12 0 4 0; #X connect 13 0 4 0; #X connect 14 0 13 0; #X connect 15 0 18 0; #X connect 16 0 4 0; #X connect 17 0 16 1; #X connect 18 0 17 0; #X connect 18 1 14 1; #X connect 20 0 3 1;
Hallo, punchik punchik hat gesagt: // punchik punchik wrote:
yes, something like that thanks, but why should i use arrays instead text files? is it faster?
Yes, it's a lot faster especially with larger textfiles.
For example to read out line number 80 you would need to bang the textfile object 80 times and get 79 useless messages coming out of the textfile object. Reading array element 80 is just a simple lookup of that number - it's one of the fastest things you can do in Pd.
You can probably use IOhannes's approach to load the textfile content into a set of tables once.
Frank Barknecht Do You RjDj.me? _ ______footils.org__
cool thanks, i have one more doubt , is there is a way to store 3 variable in one index of an array? how can i do if i would like to have 3 values rgb at one index? or should i use 3 arrays one per color?
thanks
pun.
--- On Wed, 1/21/09, Frank Barknecht fbar@footils.org wrote:
From: Frank Barknecht fbar@footils.org Subject: Re: [PD] reading colors from txt file with repeat To: pd-list@iem.at Date: Wednesday, January 21, 2009, 3:59 AM Hallo, punchik punchik hat gesagt: // punchik punchik wrote:
yes, something like that thanks, but why should i use
arrays instead text files? is it faster?
Yes, it's a lot faster especially with larger textfiles.
For example to read out line number 80 you would need to bang the textfile object 80 times and get 79 useless messages coming out of the textfile object. Reading array element 80 is just a simple lookup of that number - it's one of the fastest things you can do in Pd.
You can probably use IOhannes's approach to load the textfile content into a set of tables once.
Ciao
Frank Barknecht Do You RjDj.me? _ ______footils.org__
Pd-list@iem.at mailing list UNSUBSCRIBE and account-management -> http://lists.puredata.info/listinfo/pd-list
Hallo, punchik punchik hat gesagt: // punchik punchik wrote:
cool thanks, i have one more doubt , is there is a way to store 3 variable in one index of an array? how can i do if i would like to have 3 values rgb at one index? or should i use 3 arrays one per color?
You can only store one number per index. So you either should use 3 arrays (i.e. $0-r, $0-g, $0-b) or group three values inside one table by adjusting the indices accordingly. It's easier to show in a patch than to tell, so just look at the attachment to see what I mean.
Frank Barknecht Do You RjDj.me? _ ______footils.org__
Hallo, Frank Barknecht hat gesagt: // Frank Barknecht wrote:
You can only store one number per index. So you either should use 3 arrays (i.e. $0-r, $0-g, $0-b) or group three values inside one table by adjusting the indices accordingly. It's easier to show in a patch than to tell, so just look at the attachment to see what I mean.
Actually that's nice to have as an abstraction so I made it. It's called tabread-three and not tabread3 because of tabread4. ;)
Frank Barknecht Do You RjDj.me? _ ______footils.org__
Hi Frank
Maybe look at this concept attached tab-many.pd its more generic.
Stef
Frank Barknecht skrev:
Hallo, Frank Barknecht hat gesagt: // Frank Barknecht wrote:
You can only store one number per index. So you either should use 3 arrays (i.e. $0-r, $0-g, $0-b) or group three values inside one table by adjusting the indices accordingly. It's easier to show in a patch than to tell, so just look at the attachment to see what I mean.
Actually that's nice to have as an abstraction so I made it. It's called tabread-three and not tabread3 because of tabread4. ;)
#N canvas 27 42 393 214 10; #X msg 25 54 0.15 0.2 0.25; #X msg 51 81 0.85 0.8 0.75; #N canvas 0 0 528 452 write 0; #X obj 195 90 inlet; #X obj 424 90 inlet; #X obj 424 112 * 3; #X obj 158 379 tabwrite $0-array; #X obj 257 353 +; #X obj 237 136 0; #X obj 222 294 f; #X obj 251 293 + 1; #X obj 195 112 t b a b; #X obj 158 202 list; #X obj 158 232 list split 1; #X obj 158 258 t f b; #X obj 158 138 3; #X obj 158 160 until; #X floatatom 320 178 5 0 0 0 - - -; #X connect 0 0 8 0; #X connect 1 0 2 0; #X connect 2 0 4 1; #X connect 4 0 3 1; #X connect 5 0 6 1; #X connect 6 0 7 0; #X connect 6 0 4 0; #X connect 7 0 6 1; #X connect 8 0 12 0; #X connect 8 1 9 1; #X connect 8 2 5 0; #X connect 9 0 10 0; #X connect 10 0 11 0; #X connect 10 1 9 1; #X connect 11 0 3 0; #X connect 11 1 6 0; #X connect 12 0 13 0; #X connect 13 0 9 0; #X connect 14 0 12 1; #X connect 14 0 2 1; #X restore 25 131 pd write; #X floatatom 70 106 5 0 0 0 - - -; #N canvas 0 0 509 502 read 0; #X obj 199 34 inlet; #X obj 243 298 tabread $0-array; #X obj 199 64 * 3; #X obj 259 354 list; #X obj 294 354 t l; #X obj 106 384 list; #X obj 243 270 +; #X obj 200 180 until; #X obj 200 158 3; #X obj 199 92 t b b f b; #X obj 200 213 f; #X obj 226 213 + 1; #X obj 284 176 0; #X floatatom 370 37 5 0 0 0 - - -; #X text 418 37 <-arg?; #X obj 106 419 outlet; #X connect 0 0 2 0; #X connect 1 0 3 0; #X connect 2 0 9 0; #X connect 3 0 4 0; #X connect 3 0 5 1; #X connect 4 0 3 1; #X connect 5 0 15 0; #X connect 6 0 1 0; #X connect 7 0 10 0; #X connect 8 0 7 0; #X connect 9 0 5 0; #X connect 9 1 8 0; #X connect 9 2 6 1; #X connect 9 3 3 1; #X connect 9 3 12 0; #X connect 10 0 11 0; #X connect 10 0 6 0; #X connect 11 0 10 1; #X connect 12 0 10 1; #X connect 13 0 2 1; #X connect 13 0 8 1; #X restore 159 84 pd read; #X msg 159 128 0 0 0; #X msg 159 106 set $1 $2 $3; #X floatatom 159 54 5 0 0 0 - - -; #X obj 26 17 table $0-array; #X connect 0 0 2 0; #X connect 1 0 2 0; #X connect 3 0 2 1; #X connect 4 0 6 0; #X connect 6 0 5 0; #X connect 7 0 4 0;
oops, attached corrected
Steffen Leve Poulsen skrev:
Hi Frank
Maybe look at this concept attached tab-many.pd its more generic.
Stef
Frank Barknecht skrev:
Hallo, Frank Barknecht hat gesagt: // Frank Barknecht wrote:
You can only store one number per index. So you either should use 3 arrays (i.e. $0-r, $0-g, $0-b) or group three values inside one table by adjusting the indices accordingly. It's easier to show in a patch than to tell, so just look at the attachment to see what I mean.
Actually that's nice to have as an abstraction so I made it. It's called tabread-three and not tabread3 because of tabread4. ;)
#N canvas 27 42 393 214 10; #X msg 25 54 0.15 0.2 0.25; #X msg 51 81 0.85 0.8 0.75; #N canvas 0 0 528 452 write 0; #X obj 195 90 inlet; #X obj 424 90 inlet; #X obj 424 112 * 3; #X obj 158 379 tabwrite $0-array; #X obj 257 353 +; #X obj 237 136 0; #X obj 222 294 f; #X obj 251 293 + 1; #X obj 195 112 t b a b; #X obj 158 202 list; #X obj 158 232 list split 1; #X obj 158 258 t f b; #X obj 158 138 3; #X obj 158 160 until; #X floatatom 320 178 5 0 0 0 - - -; #X connect 0 0 8 0; #X connect 1 0 2 0; #X connect 2 0 4 1; #X connect 4 0 3 1; #X connect 5 0 6 1; #X connect 6 0 7 0; #X connect 6 0 4 0; #X connect 7 0 6 1; #X connect 8 0 12 0; #X connect 8 1 9 1; #X connect 8 2 5 0; #X connect 9 0 10 0; #X connect 10 0 11 0; #X connect 10 1 9 1; #X connect 11 0 3 0; #X connect 11 1 6 0; #X connect 12 0 13 0; #X connect 13 0 9 0; #X connect 14 0 12 1; #X connect 14 0 2 1; #X restore 25 131 pd write; #X floatatom 70 106 5 0 0 0 - - -; #N canvas 0 0 509 502 read 0; #X obj 199 34 inlet; #X obj 243 298 tabread $0-array; #X obj 199 64 * 3; #X obj 349 381 t l; #X obj 106 384 list; #X obj 243 270 +; #X obj 200 180 until; #X obj 200 158 3; #X obj 199 92 t b b f b; #X obj 200 213 f; #X obj 226 213 + 1; #X obj 284 176 0; #X floatatom 370 37 5 0 0 0 - - -; #X text 418 37 <-arg?; #X obj 106 419 outlet; #X obj 259 354 list prepend; #X connect 0 0 2 0; #X connect 1 0 15 0; #X connect 2 0 8 0; #X connect 3 0 15 1; #X connect 4 0 14 0; #X connect 5 0 1 0; #X connect 6 0 9 0; #X connect 7 0 6 0; #X connect 8 0 4 0; #X connect 8 1 7 0; #X connect 8 2 5 1; #X connect 8 3 11 0; #X connect 8 3 15 1; #X connect 9 0 10 0; #X connect 9 0 5 0; #X connect 10 0 9 1; #X connect 11 0 9 1; #X connect 12 0 2 1; #X connect 12 0 7 1; #X connect 15 0 3 0; #X connect 15 0 4 1; #X restore 159 84 pd read; #X msg 159 128 0.15 0.2 0.25; #X msg 159 106 set $1 $2 $3; #X floatatom 159 54 5 0 0 0 - - -; #X obj 26 17 table $0-array; #X connect 0 0 2 0; #X connect 1 0 2 0; #X connect 3 0 2 1; #X connect 4 0 6 0; #X connect 6 0 5 0; #X connect 7 0 4 0;