Here's something I've done using the mouse to draw and simultaneously create
sound. Admittedly primitive, with lots of room for exploration and
improvement:
Eli
(
s.waitForBoot({
var point, red, green, blue, win, view, colorTask, redChange, greenChange,
blueChange;
SynthDef(\note, {
arg freq=440, width=0.5, pan=0, amp=1, length=1;
var sig, env;
env = EnvGen.kr(Env([0,1,0],[0.012,0.012]*length, \linear), doneAction:2);
sig = VarSaw.ar(freq, 0, width);
sig = Pan2.ar(sig, pan, amp);
sig = sig * env;
Out.ar(0, sig);
}).add;
//initial color values and increments
red=0; green=0.33; blue=0.67;
redChange=0.01;
greenChange=0.015;
blueChange=0.02;
//update RGB color values 20x per sec
colorTask = Task({
{
red = (red + redChange)%2;
green = (green + greenChange)%2;
blue = (blue + blueChange)%2;
0.05.wait;
}.loop
});
//gui
win = Window("SKETCH PAD",
Rect(0,0,Window.screenBounds.width,Window.screenBounds.height),
border:true);
win.onClose = {
if(
colorTask.isPlaying,
{colorTask.stop},{});
};
view = UserView(win, Window.screenBounds);
view.clearOnRefresh = false;
view.background = Color.black;
//right click to clear sketch pad
view.mouseDownAction = {
|v, x, y, mod, butNum|
point = [x,y];
if(
butNum == 1,
{
v.drawFunc_({nil});
v.clearDrawing;
v.refresh
}, {}
);
};
//draw lines with Pen and create Synths according to mouse movement
view.mouseMoveAction = {
|v, x, y|
var penWidth=30;
v.drawFunc = {
Pen.strokeColor = Color.new(
red.fold(0,1),
green.fold(0,1),
blue.fold(0,1)
);
Pen.width = penWidth;
Pen.line(point.asPoint, ***@y);
point = [x,y];
Pen.stroke;
};
win.refresh;
Synth(\note, [
// \freq, ((x/(Window.screenBounds.width)).linlin(0,1,32,100)).midicps,
// \freq, exprand(40.0,2000.0),
\freq, ((x/(Window.screenBounds.width)).linlin(0,1,32,90).round(5) +
[0,3,7].choose).midicps,
\width, ((y/(Window.screenBounds.height)).linlin(0,1,0.001,0.5)),
// \pan, x.linlin(0,Window.screenBounds.width, -1, 1),
\pan, rrand(-1.0,1.0),
\length, penWidth
]);
};
colorTask.start;
win.front;
})
)
--
View this message in context: http://new-supercollider-mailing-lists-forums-use-these.2681727.n2.nabble.com/using-Pen-to-create-visuals-tp7613498p7613506.html
Sent from the SuperCollider Users New (Use this!!!!) mailing list archive at Nabble.com.
_______________________________________________
sc-users mailing list
info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/