[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [sc-users] multiple envelope
a small typo in the last posting. this line:
array = array.add([i,env[i*length/(width)]*height*peak]);
should have ended with "peak.reciprocal".
here's the correct (but still deficient) code:
----
e = Env.new([0,1,0],[1,1],[1,1]);
f = {|env,width=400,height=200|
var array, win, length, peak;
length = env.times.sum;//find span of time of envelope
peak = env.levels.collect({|i| i=i.abs}).maxItem; // find greatest Y (abs) value
array = [];
width.do({|i| // build an array of co-ordinates
array = array.add([i,env[i*length/(width)]*height*peak.reciprocal]); // scale the output to the window height
});
array.collect({|i| array[i]=Point.new(i[0],i[1])}); // turn them into Points
win = Rect(100,100,width,height));
win.view.background_(Color.white);
win.drawHook = {
Pen.translate(0,height/2); // move the origin halfway down the page
(array.size-2).do({|i|
Pen.beginPath;
Pen.moveTo(array[i]);
Pen.lineTo(array[i+1]);
Pen.stroke;
});
};
env.plot; // for comparison
win.refresh;
win.front;
};
f.value(e);