// title: Scribble Squiggle // author: 56228375 // description: // Alternative way of squiggling: instead of modeling the squiggle with math formulas you can also just draw it by mouse, record it and then play it back (after optionally transforming it) to drive some synths. // code: // part one: record squiggle ( // start time var startTime = thisThread.seconds ; ~allPoints = [] ; ~diffPoints = [] ; w = Window.new.front; q = UserView.new(w,w.view.bounds); q.mouseDownAction_({ | view, x, y, modifiers, buttonNumber, clickCount | ~allPoints = []; }); q.mouseMoveAction_({ | view, x, y, modifiers, buttonNumber, clickCount | ~allPoints = ~allPoints.add([x, y, thisThread.seconds-startTime].postln ); }); q.animate_(true); q.drawFunc_({ ~allPoints.do({ |pos, index| if ((index > 0), { Pen.fillColor = "000000"; Pen.line( Point(~allPoints[index-1][0], ~allPoints[index-1][1]), Point(pos[0], pos[1])); Pen.stroke; }); }); }); ) // part two: perform squiggle ( s.waitForBoot({ SynthDef(\doSomething, { | out=0, freq=440, xval, yval | var sig = 0.05*(VarSaw.ar(freq*yval.linlin(0,350,2,1), width:xval.linlin(0,350,0.2,0.9))); var env = EnvGen.ar(Env.perc(0.1),doneAction:2); sig = env*sig; Out.ar(out, sig!2); }).add; s.sync; Pdef(\playRecorded, Pbind(\instrument, \doSomething, \firstOrder, Pseq(~allPoints, 1), \secondOrder, Pseq([[0,0,0], Pseq(~allPoints.differentiate.shift(-1), 1)], 1), \degree, 5, \xval, Pfunc({ | ev | ev[\firstOrder][0]; }), // xval somewhere between 0 and 350 \yval, Pfunc({ | ev | ev[\firstOrder][1]; }), // yval somewhere between 0 and 350 \dur, Pfunc({ | ev | ev[\secondOrder][2]; }) )); Pdef(\playRecorded).play; }); )