‹ klipp av Logo iPod Touch Microphone ›

Sunday Drawings

2009-11-27 15:52 supercollider

2006 I fiddled with some simple drawing routines in SuperCollider. (swiki.hfbk-hamburg.de:8888/MusicTechnology/833). Now I've added matching (?) sound synthesis and some slight modifications to the drawing code. There are 7 parameters that are used to both generate the picture and the sound. Normally the parameters are randomised but it is possible to copy&paste a good sounding/looking set of parameters into the code to get the same drawing back.

Below is the new code + embedded vimeos.

sunday drawings2 00
sunday drawings2 01
sunday drawings2 02
sunday drawings2 03
sunday drawings2 04
sunday drawings2 05
sunday drawings2 06
sunday drawings2 07
//redFrik
(
s.latency= 0.05;
s.waitForBoot{
  var width= 640, height= 480, w, u, drawFunc, clearFunc;
  var fadeAtk= 1400, fadeSus= 700, fadeRel= 350;
  var a, b, c, d, e, f, g, i= 0, theta= 0;
  var syn= SynthDef(\sunday, {|amp= 0, a= 1, b= 1, c= 1, d= 1, e= 1, f= 1, g= 1|
    var z0= Mix(BPF.ar(LFSaw.ar([a, b]), a+b, e, amp));
    var z1= SinOsc.ar(a, Ringz.ar(z0, c.abs, f, 2pi), amp);
    var z2= SinOsc.ar(b, Ringz.ar(z0, d.abs, g, 2pi), amp);
    Out.ar(0, Pan2.ar(z0, 0, 0.3)+Pan2.ar(z1, -0.3, 0.3)+Pan2.ar(z2, 0.3, 0.3));
  }).play(s);
  s.sync;
  w= Window("sunday drawings2", Rect(128, 64, width, height), false);
  drawFunc= {
    var x, y;
    if(i==0, {
      "//---------------------".postln;
      [
        \a, a, \b, b, \c, c, \d, d, \e, e, \f, f, \g, g
      ].pairsDo{|m, n| (""++m++"="+n++";").postln};
    });
    if(i<fadeAtk, {
      theta= theta+(d*e*f);
      x= sin(theta*a%a/b*c*2pi);
      y= sin(theta*b%b/a*d*2pi);
      Pen.strokeColor= Color.grey(1, 0.5);
      Pen.translate(width*0.5, height*0.5);
      Pen.scale(f, g);
      Pen.rotate(theta);
      switch(a%3,
        0, {Pen.strokeOval(Rect.aboutPoint(Point(x*100, y*100), a, b))},
        1, {Pen.strokeRect(Rect.aboutPoint(Point(x*100, y*100), a, b))},
        2, {Pen.line(Point(x*100, y*100), Point(a*c*100, b*d*100)); Pen.stroke}
      );
      syn.set(\amp, i/fadeAtk, \a, a, \b, b, \c, c, \d, d, \e, e, \f, f, \g, g);
    });
    if(i>(fadeAtk+fadeSus), {
      clearFunc.value;
      theta= 0;
      Pen.fillColor= Color.grey(0, 5/fadeRel);
      Pen.fillRect(Rect(0, 0, width, height));
      syn.set(\amp, i.linexp(fadeAtk+fadeSus, fadeAtk+fadeSus+fadeRel, 1, 0.0001));
    });
    if(i==(fadeAtk+fadeSus+fadeRel), {
      i= 0;
    }, {
      i= i+1;
    });
  };
  clearFunc= {

    //--replace with preset from here
    a= 200.rand+1;
    b= 200.rand+1;
    c= 3.0.rand2;
    d= 3.0.rand2;
    e= 3.0.rand;
    f= 0.1.rrand(1.5)*#[1, -1].choose;
    g= 0.1.rrand(1.5)*#[1, -1].choose;
    //--to here

  };
  clearFunc.value;
  u= UserView(w, Rect(0, 0, width, height))
    .clearOnRefresh_(false)
    .drawFunc_(drawFunc)
    .background_(Color.black);
  w.front;
  CmdPeriod.doOnce({w.close});
  w.onClose= {syn.free};
  Routine({
    var nextTime;
    while({w.isClosed.not}, {
      nextTime= Main.elapsedTime+(1/60);
      u.refresh;
      (nextTime-Main.elapsedTime).max(0.001).wait;
    });
  }).play(AppClock);
};
)

‹ klipp av Logo iPod Touch Microphone ›