[sc-users] a little graphic
Julian Rohrhuber
rohrhuber at uni-hamburg.de
Wed Jan 10 15:25:41 PST 2007
// neon
(
var xx, yy, x, y, c, width, z=1, pp, zz=0, mm=10, alph=1.0;
width = 1;
w = GUI.window.new(Char.bullet, Rect(100, 100, 600, 600)).front;
w.view.background_(Color.gray(0.6));
v = GUI.userView.new(w, w.view.bounds).mouseTrackFunc_({|v,ax,ay|
x = ax; y = ay;
4.do {
[xx,
yy].choose.value([5, -5, 2, -2, 8, -8].choose *
2);
};
});
x = 200; y = 100;
xx = { |d=1| c = c.add((x = x + d) @ y ).keep(-150) };
yy = { |d=1| c = c.add(x @ (y = y + d)).keep(-150) };
c = [];
20.do {
[xx,
yy].choose.value([10, -10, 5, -5, 2, -2].choose *
2);
};
w.drawHook = {
// set the Color
try { GUI.pen.setSmoothing(false) };
GUI.pen.width = width;
z.do { |i|
Color.rand.alpha_(i.linexp(0, z-1, 1.0, alph)).set;
GUI.pen.moveTo(c[0]);
c.size.do { |i| GUI.pen.lineTo(c.wrapAt(i)) };
GUI.pen.stroke;
GUI.pen.translate([-2,
-2, 2, 2] @@ zz, [-2, 2, -2, 2]*2 @@ zz);
};
z = z + 1 % mm;
if(z % mm == 0) { zz = zz + 1; mm
= rrand(5, 20); alph = #[0.1, 1.0].choose };
};
w.refresh;
fork { loop { 0.1.wait; defer { w.refresh; } } };
)
// tetris
(
var xx, yy, x, y, c, d, width, viewheight;
var phunz, steps, nKeep;
q = q ?? ();
width = 1;
w = GUI.window.new(Char.bullet,
Rect(100, 100, 400, 400)).front;
w.view.background_(Color.black);
viewheight = w.bounds.height;
nKeep = 20;
x = 200;
y = 100;
steps = #[1, 1, 2, 2, 2, 2, 4];
v = GUI.userView.new(w, w.view.bounds);
v.mouseTrackFunc_({|v,ax,ay|
x = ax; y = ay;
phunz.(8);
q.updateData(d);
});
v.mouseEndTrackFunc_({|v,ax,ay|
q.sendData(d);
});
phunz = { arg n=1;
var scale = y.linexp(0, viewheight, 1, 40);
c = [];
n.do {
[xx,
yy].choose.value(steps.choose * #[1, -1].choose *
scale);
};
d = d.add(c).keep(nKeep.neg);
};
xx = { |d=1| c = c.add((x = x + d) @ y ) };
yy = { |d=1| c = c.add(x @ (y = y + d)) };
phunz.(20);
w.drawHook = {
try { GUI.pen.setSmoothing(false) };
GUI.pen.width = width;
d.do { |x, i|
GUI.pen.moveTo(x[0]);
x.do { |point|
blend(
Color.green,
Color.yellow,
point.y.linlin(0, viewheight, 1, -1)
).alpha_(point.y.linexp(0, viewheight,
0.5, 0.1))
.set;
GUI.pen.lineTo(point);
};
GUI.pen.stroke;
};
d = d.deepCollect(2, {
|x| x.y = x.y + 0.5 % viewheight });
};
w.refresh;
fork { loop { 0.01.wait; defer { w.refresh; } } };
)
// sound
(
p = ProxySpace(s.boot);
p.play(\out);
p.clock = TempoClock.default;
p.fadeTime = 3;
(
q.sendData = {|q, data|
var ugens;
p[\out] = {
data.do { |array|
var xdata, ydata, xmul, ymul;
array.do { |point|
xdata = xdata.add(point.x);
ydata = ydata.add(point.y);
};
xmul = 11;
ymul = 1;
ugens = ugens.addAll([
LFPulse.ar(Duty.ar(0.4, 0, Dseq(xdata,
inf) * xmul), 0, 0.5)
,
Formant.ar(Duty.ar(0.5 * ymul, 0,
Dseq(ydata, inf) * ymul), 500, Duty.ar(0.02 *
xmul, 0, Dseq(xdata, inf) * xmul))
]);
};
LPF.ar(ugens.mean, 3000) * 0.2 ! 2
}
};
);
);
// rotary hommage à Duchamp
(
var w, width, center, bounds, a,
b, c, z = 0, colors, fillOrStroke, shape;
width = 1;
w = GUI.window.new("o").front;
w.view.background_(Color.black);
colors = [Color.new255(255, 150,
0).alpha_(0.5), Color.black.alpha_(0.5)];
fillOrStroke = [GUI.pen.fillOval(_), GUI.pen.strokeOval(_)];
shape = { (2 ** rrand(1,
5)).asInteger + rrand(0, 4) }.dup(rrand(5, 7));
shape = shape.sort.reverse;
w.drawHook = {
GUI.pen.width = width;
center = 30;
GUI.pen.translate(0, 0);
z = z + 1;
GUI.pen.beginPath;
bounds =
Rect.aboutPoint(w.view.bounds.center, 100, 100);
shape.do { |i, j|
var bb;
a = sin(z * 0.12 + (j / 10));
b = sin(z * 0.12 + 0.5pi + (j / 4));
c = sin(z * 0.005);
bounds = bounds.insetBy(i, i);
bb = bounds.moveBy(13 * a, 13 * b);
colors.wrapAt(i).set;
GUI.pen.width = 30.rand;
fillOrStroke.wrapAt(i).value(bb);
};
GUI.pen.stroke;
};
w.refresh;
fork { loop { 0.04.wait; defer { w.refresh; } } };
)
--
.
More information about the sc-users
mailing list