Array creation from .do operation

Hi,
I have the following question,
how can I create an array from the values that the attached .do operation gives?
I have tried to incorporate it as a function in Array.fill but with no sucess.

(
var angle=0,point;

20.do{
angle=(angle+(360-(360/1.61803398874989484820458683436563811772030917980576))).wrap(0,360);
	point=exp(Complex(0,1)*angle.degrad).theta;

point.postln;
}
)

Replacing do with collect does exactly what you want.

1 Like

FWIW, I find myself using collectAs extensively to create IdentityDictionary’s (or Event’s):

d = [\a, \b, \c].collectAs({|key| 
	// just some trickery to fill in some data for the key	
	key -> key.asString.first.ascii
	
}, IdentityDictionary);

access via

d[\a]

this works especially well to organise Buffers:

var filenames = "path/to/files/*.wav".pathMatch; // an array of wav files, containing e.g. "ping.wav"


b = filenames.collectAs({|path| 
	var key, buffer;
	
	key = path.basename.splitext.first.asSymbol;
	buffer = Buffer.read(s, path);
	
	key -> buffer
	
}, Event);



// return buffer object
b.ping;
2 Likes