‹ Audiovisuals with SC - Example11a - harmonicity is order Audiovisuals with SC - Example12 - many mappings ›

Audiovisuals with SC - Example11b - harmonicity is disorder

See /f0blog/audiovisuals-with-sc/

//Example11b - harmonicity is disorder
//a little bit different from Example11a.
(
s.latency= 0.05;
s.waitForBoot{

  //--window setup
  var width= 640, height= 480;
  var w= Window("Example11b - harmonicity is disorder", Rect(99, 99, width, height), false);
  var u= UserView(w, Rect(0, 0, width, height));

  //--variables
  var disorder= {1.0.rand2}.dup(30);  //array of random values
  var syns= {
    SynthDef(\av, {|freq= 300, amp= 0, pan= 0|
      var z= LPF.ar(LFSaw.ar(freq), freq+2000, amp);
      Out.ar(0, Pan2.ar(z, pan));
    }).play(s);
  }.dup(30);  //max 30 voices
  s.sync;

  //--interface
  ~num= 6;
  ~columns= 10;
  ~dist= 0;

  //--main loop
  u.drawFunc= {
    Pen.translate(60, 60);
    Pen.fillColor= Color.white;  //always fill with white color
    30.do{|i|
      var x= i%~columns+(disorder[i]*~dist);
      var xx= i%~columns+(disorder[i]*(1-~dist));  //inverted
      var y= i.div(~columns)+1*100;
      x= x+(i.div(~columns)*0.25);  //shift each row a little
      if(i<~num, {
        Pen.fillOval(Rect.aboutPoint(Point(x*60, y), 20, 20));
        syns[i].set(
          \freq, xx+1*y,  //using the inverted
          \amp, 0.5/~num,
          \pan, i%~columns/~columns*2-1
        );
      }, {
        syns[i].set(\amp, 0);
      });
    };
  };

  //--window management
  u.clearOnRefresh= true;
  u.background= Color.black;
  w.onClose= {syns.do{|x| x.free}};
  w.front;
  CmdPeriod.doOnce({w.close});
  Routine({
    var nextTime;
    while({w.isClosed.not}, {
      nextTime= Main.elapsedTime+(1/60);
      u.refresh;
      (nextTime-Main.elapsedTime).max(0.001).wait;
    });
  }).play(AppClock);
};
)

//change these while the program is running
~dist= 0.5;
~dist= 0;
~dist= 1;
~num= 13;
~dist= 0;
~num= 25;
~dist= 0.1;
~dist= 0.2;
~dist= 0.3;
~columns= 8;
~num= 4;
~dist= 0;
~dist= 1;

(
Routine{
  ~columns= 9;
  400.do{|i|
    ~num= i.div(10).min(30)+1;
    ~dist= 1-cos(i%200/200*2pi).abs;
    (1/20).wait;
  };
  "done".postln;
}.play;
)

//close the window to stop or press cmd+.