Submit
Browse
Anonymous
Login
RSS
SuperCollider Code
Fork Code: List expander and contractor function
name
code content
( b = {|x,y| var arr = List[]; case {y % x.size == 0} // condition 1 { var per = y / x.size; x.size.do{|oo| var pp = 1,i = 1; arr.add( x[oo] ); while({i < per},{ arr.add(0); i = i+1; }); } } {x.size % y == 0} // condition 2 { var pp = x.size / y, i = 0, sz = x.size; while({i < sz},{ if(i % pp == 0) { arr.add(x[i]) }; i=i+1; }); }; arr }; a = [1,1,1,1]; c = b.value(a,16) // [ 1, 1, 1, 1 ] // becomes // [ 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0 ] b.value(c,4); // [ 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0 ] // becomes // [ 1, 1, 1, 1 ] )
code description
useful for expanding or reducing arrays by 2^x. I would like to know if there is a more concise way to write this! Any suggestions? (duplicate post, sorry! forgot to log in!)
use markdown for formating
category tags
comma separated, i.g. "wild, siren" (do not enter default SC class names, please)
ancestor(s)
comma separated identificators, i.g. "1-C,1-1,1-4M,1-x"
Private?
the code will be accessible by direct url and not visible in public activity
signup to submit public code without captcha
comment of change