‹ Audiovisuals with SC - Example08b - faster is slower Audiovisuals with SC - Example09b - brighter is smoother ›

Audiovisuals with SC - Example09a - brighter is sharper

See /f0blog/audiovisuals-with-sc/

//Example09a - brighter is sharper
(
s.latency= 0.05;
s.waitForBoot{

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

  //--variables
  var pat= Pn(Pshuf(#[0, 0, 0, 0, 0.1, 0.25, 0.5, 0.75, 1, 1], 8), inf).asStream;
  var syn= SynthDef(\av, {|cutoff= 2000|
    var z= LPF.ar(LFSaw.ar(#[300, 301, 80, 81]).mean, cutoff);
    Out.ar(0, Pan2.ar(z));
  }, #[0.15]).play(s);  //lag time to avoid clipping
  var cut= 0;
  var frameCount= 0;
  var drawStar= {|point, num, outer, inner|  //function that draws a star
    num.do{|i|
      Pen.moveTo(point+Polar(inner, i/num*2pi).asPoint);
      Pen.lineTo(point+Polar(outer, i/num*2pi+(pi/num)).asPoint);
      Pen.lineTo(point+Polar(inner, i+1/num*2pi).asPoint);
    };
    Pen.stroke;
  };

  //--interface
  ~radius= 100;
  ~fps= 60;
  ~num= 20;
  ~speed= 2;
  ~spread= 0;
  ~depth= 0.3;

  //--main loop
  u.drawFunc= {
    var r= ~radius+(cut*~spread);
    if(frameCount%~fps.div(~speed)==0, {  //pick a new cutoff
      cut= pat.next;  //get the next value from the stream
      syn.set(\cutoff, cut*3000+500);  //send to the synth
    });
    Pen.translate(width*0.5, height*0.5);  //offset drawing to the centre
    Pen.strokeColor= Color.white;  //always stroke with white color
    drawStar.value(Point(0, 0), ~num, r, r*(1-(cut*~depth)));
    frameCount= frameCount+1;
  };

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

//change these while the program is running
~num= 5;
~speed= 12;
~radius= 25;
~num= 25;
~spread= 25;
~radius= 150;
~depth= 0.9;
~depth= -1.25;

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