‹ Audiovisuals with SC - Example05a - left is leftAudiovisuals with SC - Example06a - louder is higher ›

Audiovisuals with SC - Example05b - left is right

See /f0blog/audiovisuals-with-sc/

//Example05b - left is right
//only one line differs from Example05b.  the one in the main loop where we invert the mapping.
(
s.latency= 0.05;
s.waitForBoot{

    //--window setup
    var width= 640, height= 480;
    var w= Window("Example05b - left is left", 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, {|pan= 0|
        var z= LPF.ar(LFSaw.ar(#[300, 301, 80, 81]).mean, 2000);
        Out.ar(0, Pan2.ar(z, pan));
    }, #[0.05]).play(s);  //short lag time to avoid clipping
    var pan= 1;

    //--interface
    ~radius= 50;
    ~fps= 10;
    ~spreadx= 240;

    //--main loop
    u.drawFunc= {
        if(u.frame%(~fps/60).reciprocal==0, {
            pan= pat.next;  //get the next value from the stream
            syn.set(\pan, pan*2-1);  //send to the synth
            pan= 1-pan;  //here we invert the mapping
        });
        Pen.translate(width*0.5, height*0.5);  //offset drawing to the centre
        Pen.fillColor= Color.white;  //always fill with white color
        Pen.fillOval(Rect.aboutPoint(Point(pan-0.5*~spreadx, 0), ~radius, ~radius));
    };

    //--window management
    u.clearOnRefresh= true;
    u.background= Color.black;
    w.onClose= {syn.free};
    w.front;
    u.animate= true;
    CmdPeriod.doOnce({if(w.isClosed.not, {w.close})});
};
)

//change these while the program is running
~radius= 150;
~radius= 25;
~fps= 30;
~fps= 15;
~spreadx= 500;
~fps= 5;
~radius= 5;

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