File: strike.scd

package info (click to toggle)
supercollider 1%3A3.13.0%2Brepack-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 80,296 kB
  • sloc: cpp: 476,363; lisp: 84,680; ansic: 77,685; sh: 25,509; python: 7,909; makefile: 3,440; perl: 1,964; javascript: 974; xml: 826; java: 677; yacc: 314; lex: 175; objc: 152; ruby: 136
file content (152 lines) | stat: -rw-r--r-- 2,864 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// strike
// click and drag to draw
// Julian Rohrhuber, 2006


// neon
(
var xx, yy, x, y, c, width, z=1, pp, zz=0, mm=10, alph=1.0;
width = 1;
w = Window("u", Rect(100, 100, 600, 600)).front;
w.view.background_(Color.gray(0.6));

v = UserView(w, w.view.bounds).mouseMoveAction_({|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.drawFunc = {
	// set the Color
	try { Pen.smoothing_(false) };
	Pen.width = width;
	z.do { |i|
		Pen.strokeColor = Color.rand.alpha_(i.linexp(0, z-1, 1.0, alph));
		Pen.moveTo(c[0]);
		c.size.do { |i| Pen.lineTo(c.wrapAt(i)) };
		Pen.stroke;
		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"
// click and drag to draw
(
var xx, yy, x, y, c, d, width, viewheight;
var phunz, steps, nKeep;

q = ();

width = 1;
w = Window("u", 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 = UserView(w, w.view.bounds);
v.mouseMoveAction_({|v,ax,ay|
	x = ax; y = ay;
	phunz.(8);
	q.updateData(d);
});
v.mouseUpAction_({|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.drawFunc = {

	try { Pen.smoothing_(false) };

	Pen.width = width;

	d.do { |x, i|
		Pen.moveTo(x[0]);
		x.do { |point|
			Pen.strokeColor = blend(
				Color.green,
				Color.yellow,
				point.y.linlin(0, viewheight, 1, -1)
			).alpha_(point.y.linexp(0, viewheight, 0.5, 0.1));
			Pen.lineTo(point);
		};
		Pen.stroke;
	};
	d = d.deepCollect(2, { |x| x.y = x.y + 0.5 % viewheight });

};
w.refresh;
{ loop { 0.015.wait; w.refresh }}.fork( AppClock );
w.onClose = { Ndef(\tetris).clear(2) };
)



// sound for "tetris"

(
q[\sendData] = {|q, data|
	Ndef(\tetris, {
		var ugens;
		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
	}).play;

};
);