1// strike
2// click and drag to draw
3// Julian Rohrhuber, 2006
4
5
6// neon
7(
8var xx, yy, x, y, c, width, z=1, pp, zz=0, mm=10, alph=1.0;
9width = 1;
10w = Window("u", Rect(100, 100, 600, 600)).front;
11w.view.background_(Color.gray(0.6));
12
13v = UserView(w, w.view.bounds).mouseMoveAction_({|v,ax,ay|
14	x = ax; y = ay;
15
16	4.do {
17		[xx, yy].choose.value([5, -5, 2, -2, 8, -8].choose * 2);
18
19	};
20
21});
22
23x = 200; y = 100;
24xx = { |d=1| c = c.add((x = x + d) @ y ).keep(-150) };
25yy = { |d=1| c = c.add(x @ (y = y + d)).keep(-150) };
26c = [];
2720.do {
28	[xx, yy].choose.value([10, -10, 5, -5, 2, -2].choose * 2);
29
30};
31
32w.drawFunc = {
33	// set the Color
34	try { Pen.smoothing_(false) };
35	Pen.width = width;
36	z.do { |i|
37		Pen.strokeColor = Color.rand.alpha_(i.linexp(0, z-1, 1.0, alph));
38		Pen.moveTo(c[0]);
39		c.size.do { |i| Pen.lineTo(c.wrapAt(i)) };
40		Pen.stroke;
41		Pen.translate([-2, -2, 2, 2] @@ zz, [-2, 2, -2, 2]*2 @@ zz);
42
43	};
44	z = z + 1 % mm;
45	if(z % mm == 0) { zz = zz + 1; mm = rrand(5, 20); alph = #[0.1, 1.0].choose };
46};
47w.refresh;
48fork { loop { 0.1.wait; defer { w.refresh; } } };
49
50)
51
52
53
54
55
56
57// "tetris"
58// click and drag to draw
59(
60var xx, yy, x, y, c, d, width, viewheight;
61var phunz, steps, nKeep;
62
63q = ();
64
65width = 1;
66w = Window("u", Rect(100, 100, 400, 400)).front;
67w.view.background_(Color.black);
68
69viewheight = w.bounds.height;
70nKeep = 20;
71x = 200;
72y = 100;
73steps = #[1, 1, 2, 2, 2, 2, 4];
74
75v = UserView(w, w.view.bounds);
76v.mouseMoveAction_({|v,ax,ay|
77	x = ax; y = ay;
78	phunz.(8);
79	q.updateData(d);
80});
81v.mouseUpAction_({|v,ax,ay|
82	q.sendData(d);
83});
84
85phunz = { arg n=1;
86	var scale = y.linexp(0, viewheight, 1, 40);
87	c = [];
88	n.do {
89		[xx, yy].choose.value(steps.choose * #[1, -1].choose * scale);
90
91	};
92	d = d.add(c).keep(nKeep.neg);
93};
94
95xx = { |d=1| c = c.add((x = x + d) @ y ) };
96yy = { |d=1| c = c.add(x @ (y = y + d)) };
97
98phunz.(20);
99w.drawFunc = {
100
101	try { Pen.smoothing_(false) };
102
103	Pen.width = width;
104
105	d.do { |x, i|
106		Pen.moveTo(x[0]);
107		x.do { |point|
108			Pen.strokeColor = blend(
109				Color.green,
110				Color.yellow,
111				point.y.linlin(0, viewheight, 1, -1)
112			).alpha_(point.y.linexp(0, viewheight, 0.5, 0.1));
113			Pen.lineTo(point);
114		};
115		Pen.stroke;
116	};
117	d = d.deepCollect(2, { |x| x.y = x.y + 0.5 % viewheight });
118
119};
120w.refresh;
121{ loop { 0.015.wait; w.refresh }}.fork( AppClock );
122w.onClose = { Ndef(\tetris).clear(2) };
123)
124
125
126
127// sound for "tetris"
128
129(
130q[\sendData] = {|q, data|
131	Ndef(\tetris, {
132		var ugens;
133		data.do { |array|
134			var xdata, ydata, xmul, ymul;
135
136			array.do { |point|
137				xdata = xdata.add(point.x);
138				ydata = ydata.add(point.y);
139			};
140			xmul = 11;
141			ymul = 1;
142			ugens = ugens.addAll([
143				LFPulse.ar(Duty.ar(0.4, 0, Dseq(xdata, inf) * xmul), 0, 0.5)
144				,
145				Formant.ar(Duty.ar(0.5 * ymul, 0, Dseq(ydata, inf) * ymul), 500, Duty.ar(0.02 * xmul, 0, Dseq(xdata, inf) * xmul))
146			]);
147		};
148		LPF.ar(ugens.mean, 3000) * 0.2 ! 2
149	}).play;
150
151};
152);
153