// title: Confetti2 // author: Henk Lasschuit // description: // Confetti2 is an old project that I wrote for my first toy computer, the Aquarius by Mattel. I liked the sound of it so much, that I rewrote it for every system that I worked with: Atari-PASCAL and a few BASIC-dialects on the Mac. Now I hope that Apple computers and SuperCollider are here to stay so I don't ever have to rewrite this again. // code: //Confetti 2 /*Imagine a box that is divided into smaller compartments. You start randomly throwing beads (or marbles or grains) into it. Wheneven one compartment is full, you stop. Check how many beads there are in a compartment whenever a bead falls and check the distribution of beads in the box after you stopped. Turn numbers into pitches. Or show numbers as ASCII-characters.For the complete experience you change maxValue to 255 and you remove '+32' where shown. This program starts with a single tone but after a while it really starts swinging*/ Server.default.boot; ( ~maxValue=31; //change maxValue to 255 for the complete experience ( /*There is a decreasing linear connection between log(freq) and value. log(freq)=log(maxfreq)-((log(maxfreq)-log(minfreq))*value/maxValue), so freq=exp(log(maxfreq)-((log(maxfreq)-log(minfreq))*value/maxValue))*/ SynthDef(\beeper, { arg value=150, pan=0; var maxfreq=10000, minfreq=50; Out.ar(0, Pan2.ar(Pulse.ar(exp(log(maxfreq)-((log(maxfreq)-log(minfreq))*value/~maxValue)), 0.5, 0.3), pan, 1)); }).send(s); ); ) ( ~maxIndex=10; ~vhighest=0; ~hhighest=0; ~vlowest = 16; ~hlowest = 16; z=40; w=Window("Confetti2", Rect(400, 300, z*~maxIndex, z*~maxIndex)).front; w.view.background_(Color.white); w.front; //function for drawing array on screen t={ w.drawHook = { for(0, ~maxIndex-1, { arg v; for(0, ~maxIndex-1, {arg h; r = Rect(h*z+10, v*z, z,z); if((v == ~vhighest) && (h == ~hhighest), { //highest value will be colored red Pen.color=Color.red; Pen.addRect(Rect(h*z, v*z, z, z)); Pen.fill; }); if (( v == ~vlowest) && (h == ~hlowest), { //lowest value will be colored green Pen.color = Color.green; Pen.addRect(Rect(h*z, v*z, z, z)); Pen.fill; }); (~tabel[v,h]+32).asAscii.asString.drawInRect(r, Font("Times", 24)); // remove +32 if maxValue > 222; this may initially cause a blank window }); }); w.refresh; }; }; //initialize array and put on screen ( Routine{ ~tabel=Array2D(~maxIndex, ~maxIndex); for(0, ~maxIndex-1, { arg v; for(0, ~maxIndex-1, {arg h; ~tabel.put(v, h,0); }); }); t.value; }.play;); p=Synth(\beeper, [\value, 150, \pan, 0]); Routine({ //make distribution var highest=0, lowest=255; v= ~maxIndex.rand; //choose random element of array h= ~maxIndex.rand; while ({~tabel.at(v,h) <= ~maxValue}, { ~tabel.put(v, h, ~tabel.at(v, h) + 1); //increase element by 1 if (~tabel.at(v,h) > highest , {highest = ~tabel.at(v,h); ~vhighest=v; ~hhighest=h;}); //find highest value t.value; //put on screen p.set(\value, ~tabel.at(v,h)); //make sound v= ~maxIndex.rand; //choose next element h= ~maxIndex.rand; 0.125.wait }); //show what was made before highest=0; lowest=255; for(0, ~maxIndex-1, { arg v; for(0, ~maxIndex-1, {arg h; if (~tabel.at(v,h) > highest, { //find highest value highest = ~tabel.at(v,h); ~vhighest = v; ~hhighest = h; }); if(~tabel.at(v,h) < lowest, { //find lowest value lowest = ~tabel.at(v,h); ~vlowest = v; ~hlowest = h; }); p.set(\value, ~tabel.at(v,h)); //make sound 0.1.wait; }); }); t.value; //put on screen and color highest and lowest value p.set(\value, ~tabel.at(~vhighest, ~hhighest), \pan, -1); //sound for highest vakue q=Synth(\beeper, [\value, ~tabel.at(~vlowest, ~hlowest), \pan, 1]); //sound for lowest value 10.wait; p.free; q.free; }).play; )